delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/10/08/15:15:09

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Trace-PostClient-IP: 68.147.131.211
From: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT Invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Free() crash my program!
Organization: Systematic Software
Message-ID: <7apdm01g16tmsfmr8e2k03hpjrfopqijgm@4ax.com>
References: <D7Kdnfji89etsfvcRVn-qA AT comcast DOT com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Lines: 45
Date: Fri, 08 Oct 2004 19:11:50 GMT
NNTP-Posting-Host: 24.71.223.147
X-Complaints-To: abuse AT shaw DOT ca
X-Trace: pd7tw3no 1097262710 24.71.223.147 (Fri, 08 Oct 2004 13:11:50 MDT)
NNTP-Posting-Date: Fri, 08 Oct 2004 13:11:50 MDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

fn Thu, 7 Oct 2004 22:57:08 -0700 in comp.os.msdos.djgpp, "JC"
<jessechao AT comcast DOT net> wrote:

>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?

What are the values of addr and len when it crashes? 
How are you getting and/or composing addr? 
Values of addr are linear addresses (segment*16 + offset) < 1088KB,
and unless you are following lists from the DOS list of lists, values
outside 0x400-0x700 (BIOS data area) may not return much in the way of
meaningful data. 

-- 
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian DOT Inglis AT CSi DOT com 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply

- Raw text -


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