Syntax
#include <umalloc.h> int _heapset(Heap_t heap, unsigned int fill);Description
Using _uheapset can help you locate problems where your program continues to use a freed pointer to an object. After you set the free heap to a specific value, when your program tries to interpret the set values in the freed object as data, unexpected results occur, indicating a problem.
_uheapset works just like _heapset, except that you specify the heap to check; _heapset always checks the default heap.
Note: Using the _uheapchk, _uheapset, and _uheap_walk functions (and their equivalents for the default heap) may add overhead to each object allocated from the heap.
This example creates a heap and allocates and frees memory from it. It then calls _uheapset to set the freed memory to a value.
#include <stdlib.h>#include <stdio.h> #include <umalloc.h> int main(void) { Heap_t myheap; char *ptr; int rc; /* Use default heap as user heap */ myheap = _udefault(NULL); if (NULL == (ptr = _umalloc(myheap, 100))) { puts("Cannot allocate memory from user heap."); exit(EXIT_FAILURE); } memset(ptr, 'A', 10); free(ptr); if (_HEAPOK != (rc = _uheapset(myheap, 'x'))) { switch(rc) { case _HEAPEMPTY: puts("The heap has not been initialized."); break; case _HEAPBADNODE: puts("A memory node is corrupted or the heap is damaged."); break; case _HEAPBADBEGIN: puts("The heap specified is not valid."); break; } exit(rc); } return 0; }Related Information