HTTP TCP server: fix realloc failure handling to prevent request buffer leak (#1990)

* Update http_tcp_server.c

* Update new_tcp_server.c
This commit is contained in:
divadiow
2026-02-13 21:48:29 +00:00
committed by GitHub
parent 3eb8ef85e7
commit 8d83b41d6c
2 changed files with 7 additions and 5 deletions

View File

@@ -95,11 +95,12 @@ static void tcp_client_thread(beken_thread_arg_t arg)
}
// grow by 1024
request.receivedLenmax += 1024;
request.received = (char*)realloc(request.received, request.receivedLenmax+2);
if (request.received == NULL) {
char *newbuf = (char*)realloc(request.received, request.receivedLenmax + 2);
if (newbuf == NULL) {
// no memory
return;
goto exit;
}
request.received = buf = newbuf;
}
request.received[request.receivedLen] = 0;
#endif

View File

@@ -85,12 +85,13 @@ static void tcp_client_thread(tcp_thread_t* arg)
}
// grow by INCOMING_BUFFER_SIZE
request.receivedLenmax += INCOMING_BUFFER_SIZE;
request.received = (char*)realloc(request.received, request.receivedLenmax + 2);
if(request.received == NULL)
char *newbuf = (char*)realloc(request.received, request.receivedLenmax + 2);
if(newbuf == NULL)
{
// no memory
goto exit;
}
request.received = buf = newbuf;
}
request.received[request.receivedLen] = 0;