cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: MemoryTracking internal adjustments

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 15 Aug 2011 22:56:53 -0700

On Mon, Aug 15, 2011 at 07:21:37PM +0200, Yang Tse wrote:
> 1) curl_docalloc() calls system's malloc() and fills memory with zeros.

I can't think of why this would be better than calloc().

> 1) curl_domalloc() calls system's malloc() and fills memory with a
> given value, currently 0xA5.

This is useful when valgrind is not being used, by filling any potential
pointers and variables with a bogus value to catch any uses of those
variables before initialization. Chances are a pointer of 0xa5a5a5a5 is
going to be invalid and will cause a segfault if dereferenced, and a variable
of 0xa5 or 0xa5a5 or similar is much more likely to be invalid than something
like 0x00 or 0xff or whatever value used to be in that heap block.

> 3) curl_dofree() fills memory with a given value, currently 0x13, and
> calls system's free().

Same thing here. Since 0x13131313 is likely to be an invalid pointer, this
will catch any dereferences of pointers after the block is freed.

valgrind will do these checks already, and better, too, but valgrind is
not available on all platforms that curl supports. This feature could
catch problems that only show up on those platforms, so I'd hate to see
it be unceremoniously dropped.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-16