Re: A debugging implementation of malloc
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Sun, 25 Jun 2006 10:13:38 +1200
jacob navia wrote:
void release(void *pp)
{
register int *ip = NULL;
int s;
register char *p = pp;
if (p == NULL) // Freeing NULL is allowed
return;
// The start of the block is two integers before the data.
p -= 2 * sizeof(int);
Maybe consider an alignment check (p divisible by sizeof(int)) and check
for p > 2*sizeof(int) before the subtraction. Paranoid, put protects
against release( 7 );
ip = (int *) p;
if (*ip == SIGNATURE) {
// Overwrite the signature so that this block
// can’t be freed again
*ip++ = 0;
s = *ip;
I'd bring s (and call it size) into the if{} scope.
ip = (int *) (&p[s - sizeof(int)]);
Another paranoid alignment check here?
--
Ian Collins.
.
- References:
- A debugging implementation of malloc
- From: jacob navia
- A debugging implementation of malloc
- Prev by Date: Re: Segfault City
- Next by Date: Re: Named parameters
- Previous by thread: Re: A debugging implementation of malloc
- Next by thread: Re: A debugging implementation of malloc
- Index(es):