Remove all server memory leaks on shutdown
This commit is contained in:
parent
c4b7495852
commit
19776081b8
3 changed files with 37 additions and 4 deletions
|
@ -22,4 +22,4 @@ 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
|
||||
./form_message.py D 127.0.0.1 700 | nc 127.0.0.1 $PORT && echo
|
||||
|
|
|
@ -50,11 +50,13 @@ int main (int argc, char **argv) {
|
|||
|
||||
signal(SIGINT, &sigint_handler);
|
||||
|
||||
int res, status;
|
||||
if ((status = pthread_join(thread_id, (void *) &res)) != 0) {
|
||||
int socket_res, status;
|
||||
if ((status = pthread_join(thread_id, (void *) &socket_res)) != 0) {
|
||||
fprintf(stderr, "join worker thread: %s\n", strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
teardown_frames();
|
||||
|
||||
return socket_res;
|
||||
}
|
|
@ -250,4 +250,35 @@ int delete_frame(struct Rule* rule) {
|
|||
|
||||
pthread_rwlock_unlock(&persist_lock);
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
void teardown_frames() {
|
||||
pthread_rwlock_wrlock(&persist_lock);
|
||||
|
||||
struct Frame *frame_cursor = persist_head;
|
||||
|
||||
while (frame_cursor != NULL) {
|
||||
struct Frame *next = frame_cursor->next;
|
||||
|
||||
struct LogFrame *log_cursor = frame_cursor->log;
|
||||
while (log_cursor != NULL) {
|
||||
struct LogFrame *next = log_cursor->next;
|
||||
free(log_cursor);
|
||||
log_cursor = next;
|
||||
}
|
||||
|
||||
if (frame_cursor->rule.ip.end != NULL) {
|
||||
free(frame_cursor->rule.ip.end);
|
||||
}
|
||||
|
||||
if (frame_cursor->rule.port.end != NULL) {
|
||||
free(frame_cursor->rule.port.end);
|
||||
}
|
||||
|
||||
free(frame_cursor);
|
||||
|
||||
frame_cursor = next;
|
||||
}
|
||||
|
||||
pthread_rwlock_unlock(&persist_lock);
|
||||
}
|
Reference in a new issue