cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem caused by CURLDEBUG

From: James Housley <jim_at_thehousleys.net>
Date: Sun, 22 Oct 2006 19:28:15 -0400

On Oct 22, 2006, at 6:11 PM, Daniel Stenberg wrote:

> On Sun, 22 Oct 2006, James Housley wrote:
>
>> The default mode of CURLDEBUG is to map free() to curl_dofree(),
>> which is fine most of the time. However, if an external library
>> does memory allocation it is not possible to free the memory
>> without an error or warning.
>
> Sure there is, you can use (free)(ptr). But of course there's been
> no NO need for such a call yet, so I think that's a fine reason for
> free() to work as it does.
>
> I'd say that the best approach is to add wrappers for the new
> memory allocating functions too, so that the memory leak/track
> system works for these too.

What would be required to do this?

>
> Are you referring to some libssh2 calls?

Yeah, libssh2_session_last_error() gets the last error number and
retrieves the error string (optional) and returns a pointer to it.
You can have the library manage freeing the memory or you can free
the memory. I had wanted to free the memory, but was getting errors.

>
>> Lets take some very, very simple code.
>>
>> {
>> char *str;
>> asprintf(&str, "A simple print\n");
>> free(str);
>> }
>
> Yes sure, but you should never call this function from within libcurl.

Why not? That is a great function, since you can't ever get a buffer
overrun.

>
>> The problem I ran into was a library, on request, allocating a
>> buffer for an error string.
>
> Then we should make a wrapper for libcurl that makes it return a
> pointer that curl_dofree() can free(). That way we can also make
> sure that we never leak memory, which I consider a very valuable help.

Jim

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
jeh@FreeBSD.org      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
Fortune Not Found:
Abort, Retry, Ignore?
Received on 2006-10-23