Fix memory leaks caused by abandoned threads

This commit is contained in:
akp 2023-11-11 18:41:02 +00:00
parent 496e08f9d9
commit c4b7495852
2 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
PORT=$1
./form_message.py A 68.108.144.151 40-4000 | nc 127.0.0.1 $PORT && echo
./form_message.py A 192.168.0.0-192.168.0.255 80 | nc 127.0.0.1 $PORT && echo
./form_message.py A 127.0.0.1 700 | nc 127.0.0.1 $PORT && echo
echo
./form_message.py C 68.108.143.151 350 | nc 127.0.0.1 $PORT && echo
./form_message.py C 68.108.144.151 40 | nc 127.0.0.1 $PORT && echo
./form_message.py C 192.168.0.4 80 | nc 127.0.0.1 $PORT && echo
./form_message.py C 68.108.144.151 400 | nc 127.0.0.1 $PORT && echo
./form_message.py C 127.0.0.1 700 | nc 127.0.0.1 $PORT && echo
echo
./form_message.py L | nc 127.0.0.1 $PORT && echo
echo
./form_message.py D 192.168.0.0-192.168.0.255 80 | nc 127.0.0.1 $PORT && echo
./form_message.py D 68.108.144.151 40-4000 | nc 127.0.0.1 $PORT && echo
./form_message.py D 127.0.0.1 700 | nc 127.0.0.1 $PORT && echo

View file

@ -100,7 +100,7 @@ void handle_connection(int *sdptr) {
fprintf(stderr, "[%d] Operation: %c, message length: %zu\n", sd, operation, message_length);
char *data;
char *data = NULL;
if (message_length != 0) {
data = (char *) malloc(sizeof(char) * message_length);
@ -210,6 +210,12 @@ int accept_loop(int sd) {
(void *) handle_connection,
&new_sd
);
int status = pthread_detach(thread_id);
if (status != 0) {
perror("failed to detatch thread");
return 1;
}
}
return 0;
}