Skip to content

Commit

Permalink
Fix the memory leak In recent request link list.
Browse files Browse the repository at this point in the history
The add_log_csp() function is used to record recent request. The function store the request with a C++ style link chain.
When the requests in the link chain get to the max_log_clients_count, function will remove the first link from the link chain, and here is the problem.
The removal of the link action just change the pointer of the first link, so the memory of the old first link will be no reference anymore. The memory leak happens.
With Instruments, you will find the leak track the memory on zalloc() in this function.
What I do is just create a temporary reference for the first link that should be remove from the link chain, and free the memory after the old first link is removed.
Without this memory leak, the thread should be running in a better situation.
  • Loading branch information
so898 authored May 17, 2017
1 parent d1f8c1f commit d5ceded
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Library/ShadowPath/ShadowPath/Privoxy/jcc.m
Original file line number Diff line number Diff line change
Expand Up @@ -3369,7 +3369,9 @@ static void add_log_csp(struct client_state *csp) {

if (log_clients_count > max_log_clients_count) {
log_clients->csp->flags &= ~CSP_FLAG_LOG_REQUEST;
struct log_client_states *tmp = log_clients;
log_clients = log_clients->next;
free(tmp);
log_clients_count --;
}
unlock_log_request();
Expand Down

0 comments on commit d5ceded

Please sign in to comment.