This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: cygwin programs: realloc() segfault with library v1.3.1
- To: "Cygwin Mailing List" <cygwin at cygwin dot com>
- Subject: Re: cygwin programs: realloc() segfault with library v1.3.1
- From: Benjamin Riefenstahl <Benjamin dot Riefenstahl at ision dot net>
- Date: 02 May 2001 19:00:49 +0200
- References: <001001c0d192$1cb70240$0101a8c0@luckynet.adm>
"Thunder from the hill" <thunder@ngforever.de> writes:
> Again, this is the failing source code. Whenever realloc() is used
> in sendfile(), the MicroHTTPD segfaults.
As Chris says, you should limit examples. Anyway I looked at your
code and your use of realloc(). You never do anything with the result
of your calls. That won't work. realloc() is designed to be used as
void * some_buffer = NULL;
...
some_buffer = realloc( some_buffer, newlen );
or better, with minimal error handling:
void * some_buffer = NULL;
void * temp;
...
temp = realloc( some_buffer, newlen );
if( NULL != temp ) some_buffer = temp;
In your code OTOH, all the allocated memory returned by realloc() is
just ignored so your code continues to read and write from the (now
probably invalid) previous pointer.
Note also that you will have to redesign the interface for your
clear() function to account for this usage.
so long, benny
--
ISION Internet AG
Benjamin Riefenstahl
mailto:benjamin.riefenstahl@ision.net
Harburger Schlossstr. 1
D-21079 Hamburg
http://www.ision.net
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple