curl-library
RE: Possible memory leak in libcurl?
Date: Thu, 13 Jun 2002 09:09:33 +0200 (MET DST)
On Wed, 12 Jun 2002, Gautam Mani wrote:
> I have upgraded to 4.9.7 and it looks better ...
It is called 7.9.7! :-)
> although there is still a small leak - it is still at the same place; and
> memanalyse of a small section gives me:
I wouldn't call it a "leak" since the memory is fully tracked and is removed
fine when you use curl_easy_cleanup().
> At 4588c4, there's 128 bytes.
> allocated by /install/curl-7.9.6/lib/hostip.c:499
> At 458984, there's 128 bytes.
> allocated by /install/curl-7.9.6/lib/hostip.c:499
> At 458ac4, there's 128 bytes.
> allocated by /install/curl-7.9.6/lib/hostip.c:499
> At 458704, there's 256 bytes.
> allocated by /install/curl-7.9.6/lib/url.c:1437
>
> The 256 bytes allocated are freed in the next iteration, so that is not a
> problem. The main issue is the 128 bytes allocated at hostip:499. Any
> pointers?
The function (that allocates memory on hostip.c:499) is called
Curl_getaddrinfo(). It resolves names (for IPv4-only stacks). This particular
case is used when it converts a numerical IP string to a 'struct hostent'.
Curl_getaddrinfo() gets called from Curl_resolv().
Curl_resolv() is the generic resolver-function used within libcurl. It is
protocol independent and it manages the DNS cache and stuff too. It means
that it should use cached information if there is any, or use
Curl_getaddrinfo() to resolve the name if there's nothing in the cache.
To track this down, you should set a break-point in Curl_resolv() and see
what it does on two invokes using the same name and port.
To reduce the amount of memory used for the DNS caching, you can disable the
cache completely or you can set the DNS cache time to a minimum. It will of
course also give you higher risks of resolving the same DNS names multiple
times instead of just re-using the cache entries.
Hm. It strikes me here and now, that we cache names and port combinations as
that's what we need to do for IPv6 stacks, but there's an improvement for
IPv4 stacks to be made here. It could very well cache on names only and thus
reach better results on repeated uses with FTP (since FTP tends to give lots
of different port numbers for the data connection).
-- Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/ _______________________________________________________________ Don't miss the 2002 Sprint PCS Application Developer's Conference August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlinkReceived on 2002-06-13