commit 12b936afa0b195c86d6c1e97e59198c0f6b17e51
parent 18d0851e865fcae376afa9af99f3667291fd8146
Author: benjamin paul <bpaul@bpaul.xyz>
Date: Sun, 1 Aug 2021 17:45:19 +1000
fix memory thing
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tcp.c b/tcp.c
@@ -71,13 +71,14 @@ read_socket(int sock) {
buf2 = malloc(BUF_SIZE);
memset(buf, 0, BUF_SIZE);
+ memset(buf2, 0, BUF_SIZE);
/* Keep reading until done */
do {
read_size = recv(sock, buf2, BUF_SIZE, 0);
cur_size += read_size;
- buf = realloc(buf, cur_size);
+ buf = realloc(buf, cur_size+1);
strcat(buf, buf2);
} while (read_size == BUF_SIZE);