X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f NNTP-Posting-Date: Fri, 08 Oct 2004 00:57:03 -0500 From: "JC" Newsgroups: comp.os.msdos.djgpp Subject: Free() crash my program! Date: Thu, 7 Oct 2004 22:57:08 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Lines: 33 NNTP-Posting-Host: 24.6.123.143 X-Trace: sv3-p9jUwCMh7ScH1vXWRpgGKASY0T5w38521k81EH3KyHwfB25E0akLvmtdNHWT9HwiRFYnEhWJGx30JI0!D+GZyimZDx7ysIi16fxEQ/wFJP4n2NS7Mp2QAIPEpFt0qbRexUruqSuBQ/+k X-Complaints-To: abuse AT comcast DOT net X-DMCA-Complaints-To: dmca AT comcast DOT net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.19 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi, 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 ... According to the FAQ, this might happen if the code put data into the buffer that is longer than malloc. But my code just read the data from buffer and free() them. How come I had this crash? I also noticed: if the contents of the buffer are all zeros (unused area?), it worked fine. But if the buffer had data in it other than 0 (code? data?), most likely it will crash. Anyone can help me on this? Thanks in advance.