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

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Message-ID: <416646E3.1090000@eik.bme.hu>
Date: Fri, 08 Oct 2004 09:50:59 +0200
From: solyom <solyom AT eik DOT bme DOT hu>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.1) Gecko/20040707
X-Accept-Language: hu, en-us, en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Free() crash my program!
References: <D7Kdnfji89etsfvcRVn-qA AT comcast DOT com> <41663c2c$0$179$cc7c7865 AT news DOT luth DOT se>
In-Reply-To: <41663c2c$0$179$cc7c7865@news.luth.se>
Reply-To: djgpp AT delorie DOT com

Martin Str|mberg wrote:

>JC <jessechao AT comcast DOT net> wrote:
>  
>
>>I used djgpp to develop a simple program, using dosmemget(),
>>to dump some DOS memory. The code is like following:
>>    
>>
>
>  
>
>>    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
>>    
>>
>
>  
>
>>Anyone can help me on this?
>>    
>>
>
>1. Remove that UINT8 * cast.
>
>2. If that doesn't help you need to give more information, because
>malloc() and free() work fine so it must be something else.
>
>
>Right,
>
>						MartinS
>
>  
>
Removing the cast doesn't make any difference for free(). The cast 
simply says that p should be considered as a pointer to UINT8 instead of 
o void. Free may crash if there is a memory overwrite somewhere after 
the comment

Code to printf the contents in *p

When the memory gets corrupted free() may fail.

Andras

- Raw text -


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