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" 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> Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=ISO-8859-1 X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 2.2.2 In-reply-to: (jessechao@comcast.net) Subject: Re: Free() crash my program! References: 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 Precedence: bulk > From: "JC" > 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.