delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/05/02/15:26:14

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
To: "Cygwin Mailing List" <cygwin AT cygwin DOT com>
Subject: Re: cygwin programs: realloc() segfault with library v1.3.1
References: <001001c0d192$1cb70240$0101a8c0 AT luckynet DOT adm>
From: Benjamin Riefenstahl <Benjamin DOT Riefenstahl AT ision DOT net>
Date: 02 May 2001 19:00:49 +0200
In-Reply-To: "Thunder from the hill"'s message of "Mon, 30 Apr 2001 09:21:33 -0700"
Message-ID: <ubspb1y9q.fsf@work1.work.maz.net>
Lines: 37
User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7
MIME-Version: 1.0

"Thunder from the hill" <thunder AT ngforever DOT 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 DOT riefenstahl AT ision DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019