Mail Archives: djgpp/2000/02/28/18:21:42
"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 -