cygwin programs: realloc() segfault with library v1.3.1
Benjamin Riefenstahl
Benjamin.Riefenstahl@ision.net
Wed May 2 10:02:00 GMT 2001
"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
More information about the Cygwin
mailing list