Message-ID: <38BA981C.A1D17E8F@corel.com> Date: Mon, 28 Feb 2000 10:45:32 -0500 From: Jonathan Meunier 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 .