Syntax
#include <umalloc.h> int _uheapchk(Heap_t heap);Description
_uheapchk works just like _heapchk, except that you specify the heap to check; _heapchk 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 performs memory operations on it. It then calls _uheapchk to validate the heap.
#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 = _ucalloc(myheap, 100, 1))) { puts("Cannot allocate memory from user heap."); exit(EXIT_FAILURE); } *(ptr - 1) = 'x'; /* overwrite storage that was not allocated */ if (_HEAPOK != (rc = _uheapchk(myheap))) { 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); } free(ptr); return 0; /**************************************************************************** The output should be similar to : A memory node is corrupted or the heap is damaged. ****************************************************************************/ }Related Information