heapcheckfree
raw OCR
Checks the free blocks on the heap for a constant value.
Defined in header <alloc.h>
Syntax
#include <alloc.h>
int heapcheckfree(unsigned int fillvalue);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Return value
The return value is less then zero for an error and greater than zero for success. The return values and their meaning is as follows:
| _HEAPEMPTY | no heap (value 1). |
| _HEAPOK | heap is accurate (value 2). |
| _HEAPCORRUPT | heap has been corrupted (value -1). |
| _BADVALUE | a value other than the fill value was found (value -3). |
See also
Example
#include <stdio.h>
#include <alloc.h>
#include <mem.h>
#define NUM_PTRS 10
Mefine NUM_BYTES 16
int main(void)
{
char *arraY[ NUM_PTRS
int i, res;
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( heapfillfreel 1 ) < 0 ) {
printf( "Heap corrupted. \n" );
return 1;
}
for( i = 1; i < NUM_PTRS; i += 2 )
memset( array [ i ], 0, NUM_BYTES );
res = heapcheckfree ( 1 );
if( res < 0 )
switch( res ) {
case _HEAPCORRUPT:
printf( "Heap corrupted. \n" );
return 1;
case _BADVALUE:
printf ( value in free space.\n"
return 1; ■
default:
printf ( "Unknown error.\n"
return 1;
printf( "Test successful.\n"
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/alloc.h/heapcheckfree/
· short form /3.1/heapcheckfree/