### _uheapchk -- Validate Memory Heap

Format

>     #include <umalloc.h>
>     int _uheapchk(Heap_t heap);

Language Level: Extension
_uheapchk checks the heap you specify for minimal consistency by checking all allocated and freed objects on the heap.

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

Return Value
_uheapchk returns one of the following values, defined in both <umalloc.h> and <malloc.h>:

_HEAPBADBEGIN | The heap specifed is not valid. It may have been closed or destroyed.
_HEAPBADNODE | A memory node is corrupted, or the heap is damaged.
_HEAPEMPTY | The heap has not been initialized.
_HEAPOK | The heap appears to be consistent.

Example
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 <malloc.h>

    int main(void)
    {
       char *ptr;
       int  rc;

       if (NULL == (ptr = (char*)malloc(10))) {
          puts("Could not allocate memory block.");
          exit(EXIT_FAILURE);
       }
       *(ptr - 1) = 'x';      /* overwrites storage that was not allocated */

       if (_HEAPOK != (rc = _heapchk())) {
          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.
       *******************************************************************/
    }

Managing Memory with Multiple Heaps
Memory Management

_heapchk -- Validate Default Memory Heap
_heapmin -- Release Unused Memory from Default Heap
_uheapset -- Validate and Set Memory Heap
_uheap_walk -- Return Information about Memory Heap
<umalloc.h>