So after a little further consideration it looks like your very good test is exposing an artifact of MemScope...The original buffer allocated as new_rb is not in fact leaked at all. That memory is reclaimed in the free(in_buffer), but MemScope appears to still think the actual block - assigned to new_rb - has never been freed.
If this is what is happening in the cURL code, then perhaps I don't have an issue after all. It's a limitation of the memory inspection process. This is the best possible resolution, in my mind. A phantom/non-existent memory leak is much better than a real leak... Matt -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Lars Nilsson Sent: Tuesday, February 22, 2011 2:21 PM To: libcurl development Subject: Re: Apparent memory leak deep in cURL library; requesting assistance On Tue, Feb 22, 2011 at 1:46 PM, Fisher, Matt <[email protected]> wrote: > * The 20 byte buffer being leaked is allocated at line 1188 (using 7.21.3 > code) of http.c - the one call to realloc() in Curl_add_buffer(). > * This same line 1188 is executed three times during a single > curlMlti_perform(). The first time, the calling sequence is Curl_do(line > 5336)->Curl_http(line 2537)->Curl_add_buffer(line 1188), and 20 bytes are > allocated - new_size is 20 - and this is the 20 bytes that is being leaked. > * The second time line 1188 is executed the calling sequence is Curl_do(line > 5336)->Curl_http(line 2541)->Curl_add_bufferf(line > 1145)->Curl_add_buffer(line 188), new_size is 122, and this allocation is > properly freed. > * The third time line 1188 is executed the calling sequence is again > Curl_do(line 5336)->Curl_http(line 2874)->Curl_add_buffer(line 1188), > new_size is 488, and again is properly freed. > > It is always that first 20 byte allocation that is getting leaked. Maybe you could create a test program along the lines of int main() { char *new_rb = NULL; char *in_buffer = NULL; new_rb = malloc(20); in_buffer = new_rb; in_buffer = realloc(in_buffer, 122); in_buffer = realloc(in_buffer, 488); free(in_buffer); return EXIT_SUCCESS; } and see if MemScope detects any problems? Lars Nilsson ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
