added invalid socket check to read_socket function

This commit is contained in:
Václav Šmejkal 2023-02-15 20:06:08 +01:00
parent b52f86a9a6
commit 72305929b2
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -52,6 +52,8 @@ int main(void)
received = read_socket(accepted);
if (received == NULL) continue; //FAILED
printf("Received:\n%s\n\n", received);
why2_deallocate(received);
@ -65,6 +67,12 @@ int main(void)
char *read_socket(int socket)
{
if (socket == -1)
{
fprintf(stderr, "Reading socket failed.");
return NULL;
}
long content_size = 0;
char *content = NULL;
@ -78,4 +86,4 @@ char *read_socket(int socket)
if (recv(socket, content, content_size, 0) != content_size) why2_die("Reading socket failed!");
return content;
}
}