_heapchk
Go Up to malloc.h Index
Contents
Header File
malloc.h
Prototype
int _heapchk(void);
Description
Checks and verifies the heap.
_heapchk walks through the heap and examines each block, checking its pointers, size, and other critical attributes.
Return Value
One of the following values:
HEAPBADNODE | corrupted heap block has been found |
HEAPEMPTY | No heap exists |
_HEAPOK | The heap appears to be uncorrupted |
Portability
POSIX | ANSI C | ANSI C++ | Win32 | Win64 | macOS | |
---|---|---|---|---|---|---|
_heapchk | + |
Example
#include <stdio.h>
#include <alloc.h>
#define NUM_PTRS 10
#define NUM_BYTES 16
int main(void) {
char *array[NUM_PTRS];
int i;
for (i = 0; i < NUM_PTRS; i++)
array[i] = (char *) malloc(NUM_BYTES);
for (i = 0; i < NUM_PTRS; i += 2)
free(array[i]);
if (heapcheck() == _HEAPCORRUPT)
printf("Heap is corrupted.\n");
else
printf("Heap is OK.\n");
return 0;
}