cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [EXAMPLE] Bug in getinmemory.c

From: Martin Möller <moeller.akt_at_googlemail.com>
Date: Tue, 10 May 2011 21:28:46 +0200

Am 10.05.11 20:50 schrieb "Dan Fandrich" unter <dan_at_coneharvesters.com>:

> On Tue, May 10, 2011 at 07:42:52PM +0200, Martin Möller wrote:
>> I found a bug in getinmemory.c in docs/examples.
>> This version misuses realloc: It resizes a chunk of memory, but doesn?t take
>> into
>> account that the realloced memory address changes.
>
> If realloc changes the memory address, it is responsible for moving the
> contents of the old block to the new one. At worst, the code as it stands
> will suffer from a memory leak if the realloc fails, but it should execute
> fine. Are you seeing an actual problem when running the example?
>
As with FreeBSD, this is only true if you realloc() a memory block of lesser
size, but not for a larger one, than the previous one (which is done by
getinmemory). There should be garbage output on such systems.

Man Page of realloc() on FreeBSD:
http://www.freebsd.org/cgi/man.cgi?query=realloc&apropos=0&sektion=0&manpath
=FreeBSD+8.2-RELEASE&format=html

Hopefully this helps,
Martin

>>>> Dan
> -------------------------------------------------------------------
> 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
Received on 2011-05-10