www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/28/18:21:42

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Prevent crash on free()
Date: 28 Feb 2000 14:07:48 -0800
Organization: InterWorld Communications
Lines: 38
Message-ID: <837lfp56bv.fsf@mercury.st.hmc.edu>
References: <89e5e3$8g1$1 AT cubacola DOT tninet DOT se> <89e72m$hpt$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <89e7oq$cmv$1 AT cubacola DOT tninet DOT se> <89ecto$jum$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <89ee3g$8pf$1 AT zingo DOT tninet DOT se>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 951775802 88885 134.173.45.219 (28 Feb 2000 22:10:02 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 28 Feb 2000 22:10:02 GMT
User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Marcus" <mesthlm AT hem DOT passagen DOT se> writes:

> *sigh*
> You are kidding with me, right? I DON'T want to protect any programmer.
> I take it again. I have a string, ok?
> How do I know if this string is not automatic freed?
> 
> If I have a function like this
> func (char* str)
> 
> Is it impossible to know if the function have been called this way
> func ("...");
> or
> char* a = malloc(10);
> func (a);
> ?

Generally, yes.  You may be able to hack together a DJGPP-specific way
to tell, but it will break on other systems or other DJGPP versions.

The usual technique is to define it in the documentation, along with
the other parameters of the function and their meanings.  I.e. "The
string passed should be allocated with malloc".  There are some
semi-standard functions that work like this, often ones that will use
realloc to grow or shring the string as needed.

> Do you understand what I mean? And what is YAMD?

YAMD is Yet Another Malloc Debugger.  It's a tool I wrote to help in
hunting down malloc-related bugs (freeing what you shouldn't,
overrunning buffers, etc).  You can get it from:

http://www3.hmc.edu/~neldredge/yamd/

-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


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