Mail Archives: djgpp/2000/02/29/13:42:34
Marcus <mesthlm AT hem DOT passagen DOT se> wrote:
> *sigh*
> You are kidding with me, right? I DON'T want to protect any programmer.
I'm most definitely not kidding you. But now you finally explained
your problem in a way that I (and others) managed to understand, I see
that I must have misunderstood completely what you were asking. Your
original question was just 'how do I know if it's safe to call free()
with a given pointer?'
> 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);
> ?
Essentially, yes, it is. Anyway, it is none of your function's
business to free() the memory. Let the caller take care of that.
After all, it may be that this piece of memory may be needed by other
parts of the calling routine, later, so what good would it do to free
it?
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -