Subject: Re: 0xdeadbeef memory reference
To: Ljubisa Milenkovic <firstname.lastname@example.org>
From: Jaromír <email@example.com>
Date: 07/06/2001 09:54:26
Ljubisa Milenkovic wrote:
> And to free:
> #define LFREE(t) free (&t, M_TEMP)
Assuming the 't' is pointer to the previously allocated memory, this
is wrong and seems like it would cause ramdom piece of memory to be freed
(depending on where (t) came from, it could be stack or something else).
You should use 'free(t, M_TEMP)', and set (t) to NULL afterwards manually.
The freed memory contents are set to 0xdeadbeef to detect when memory
is used after it's freed, the idea being the bogus value would cause
a crash/panic. Really good for debugging. AFAIK it's only done in kernels
with DIAGNOSTIC option.
> If I set the pointer to point to NULL (after LFREE(p)) is that memory
Yes, of course. You can do whatever you like with the pointer
after the memory is freed via free(9).
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!