previous | start | next

Check for Invalid Pointer

The malloc.c file contains a partial check that a pointer is actually pointing to the "payload" portion of a block on the heap.

static void checkblock(void *bp)
{
    if ((size_t)bp % 8)
        printf("Error: %p is not doubleword aligned\n", bp);
    if (GET(HDRP(bp)) != GET(FTRP(bp)))
        printf("Error: header does not match footer\n");
}

The void

        mm_free(void *bp) 
     

function should also check that the pointer bp is actually pointing to the "payload" of an allocated block on the heap before executing code to free it.

Otherwise, the heap could become corrupted!



previous | start | next