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 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: <41663c2c$0$179$cc7c7865 AT news DOT luth DOT se> In-Reply-To: <41663c2c$0$179$cc7c7865@news.luth.se> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Martin Str|mberg wrote: >JC 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