From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Prevent crash on free() Date: 29 Feb 2000 16:02:19 GMT Organization: Aachen University of Technology (RWTH) Lines: 28 Message-ID: <89gqib$jah$1@nets3.rz.RWTH-Aachen.DE> 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: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 951840139 19793 137.226.32.75 (29 Feb 2000 16:02:19 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 29 Feb 2000 16:02:19 GMT User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586)) Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Marcus 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.