delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/29/08:52:17

Date: Tue, 29 Feb 2000 11:31:45 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Marcus <mesthlm AT hem DOT passagen DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: Prevent crash on free()
In-Reply-To: <89ee3g$8pf$1@zingo.tninet.se>
Message-ID: <Pine.SUN.3.91.1000229113133.22619Q-100000@is>
MIME-Version: 1.0
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

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.

- Raw text -


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