delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/10/08/07:52:12

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Fri, 08 Oct 2004 13:48:08 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-ID: <01c4ad2c$Blat.v2.2.2$d33d6940@zahav.net.il>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 2.2.2
In-reply-to: <D7Kdnfji89etsfvcRVn-qA@comcast.com> (jessechao@comcast.net)
Subject: Re: Free() crash my program!
References: <D7Kdnfji89etsfvcRVn-qA AT comcast DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "JC" <jessechao AT comcast DOT net>
> Date: Thu, 7 Oct 2004 22:57:08 -0700
> 
>     p = (UINT8 *)malloc(len+1);
>     if (p == NULL)
>     {
>         ...
>     }
>     dosmemget(addr, len, p);
>     /* Code to printf the contents in *p */
>  ...
>  free(p);
> 
> The code compiled & ran fine. But when the code execute
> the free(). The code crashed and got SIGSEG error:
> 
>     Exiting due to signal SIGSEGV
>     General Protection Fault at eip=00006ac4
>     ...
> 
> According to the FAQ, this might happen if the code put
> data into the buffer that is longer than malloc.

Or because it overwrote the buffer's end during processing.

Overall, I agree with the suggestion already posted here: show more of
your code between the calls to dosmemget and free, the problem is
likely somewhere there.

You could also debug this problem yourself, e.g. by setting a
data-write breakpoint (a.k.a. watchpoint) at the end of the buffer
allocated with malloc, and then see if some code except dosmemget
writes there.

- Raw text -


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