cURL / Mailing Lists / curl-library / Single Mail

curl-library

free(): invalid pointer

From: Plamen Barzakov <barzakov_at_gmail.com>
Date: Tue, 22 Aug 2006 12:43:24 +0200

I am building a program using libcurl 7.15.3 and I get that message at a
certain point:

*** glibc detected *** free(): invalid pointer: 0x08066f24 ***

Debuging the program shows that the program dies after a call to
Curl_safefree();
I played around with the debugger a little bit and got different results:
the invalid pointer is conn->allocptr.host. Relinking the program with the
library results in different behaviour: another free(); invalid pointer,
this time when trying to free conn->proto.generic. I didn't have time to
browse the code responsible for allocating and setting those variables, but
I found out that the implementation of Curl_safefree(); is not that safe
actually...

void Curl_safefree(void *ptr) {
if(ptr) free(ptr);
}

This is the way most of the people implement such "safe" functions for
allocating and deallocating memory, but it's generally bad. The reason is
that if ptr does not point to an allocated memory, we never know if it's
NULL or not.
Received on 2006-08-22