heapcheck

From RAD Studio
Jump to: navigation, search

Go Up to alloc.h Index


Header File

alloc.h

Prototype

int heapcheck(void);

Description

Checks and verifies the heap.

heapcheck walks through the heap and examines each block, checking its pointers, size, and other critical attributes.

Return Value

The return value is less than 0 for an error and greater than 0 for success. The return values and their meaning are as follows:

_HEAPCORRUPT Heap has been corrupted
_HEAPEMPTY No heap
_HEAPOK Heap is verified

Portability

POSIX ANSI C ANSI C++ Win32 Win64 macOS
heapcheck +

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;
}