Re: A debugging implementation of malloc



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.
.