delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/28/11:51:42

Message-ID: <38BA981C.A1D17E8F@corel.com>
Date: Mon, 28 Feb 2000 10:45:32 -0500
From: Jonathan Meunier <jonathanm AT corel DOT com>
X-Mailer: Mozilla 4.7 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Prevent crash on free()
References: <89e5e3$8g1$1 AT cubacola DOT tninet DOT se>
NNTP-Posting-Host: 120.150.3.42
X-Trace: 28 Feb 2000 10:58:52 -0500, 120.150.3.42
Lines: 22
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Marcus wrote:
> 
> Hi!
> How can I test if a memory is permanently alloced with malloc? To prevent
> crash on free().
> Like:
> void safefree (void* mem)
> {
>   if(memory_is_malloc(mem))
>     free(mem);
> }
> Because the program crash if I use free careless.

A safe way would be to put your pointer to 0 everytime you free it..

if(mem) {
  free(mem);
  mem = 0;
}

	.(Trancelucid).
	  .  Jaune  .

- Raw text -


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