Date: Tue, 29 Feb 2000 11:31:45 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Marcus cc: djgpp AT delorie DOT com Subject: Re: Prevent crash on free() In-Reply-To: <89ee3g$8pf$1@zingo.tninet.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: dj-admin AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Mon, 28 Feb 2000, Marcus wrote: > 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); > ? The usual paradigm in C programs is to place the responsibility of freeing memory on the same code which allocated that memory. So the code which allocates memory should keep track of what it allocates and free it as needed. If you are talking about some implementation of a function which frees memory, the usual way to do this is to have some data structure which records allocated blocks, and check the pointer against that data structure. This requires cooperation between the function which allocates memory and the one which frees it.