heapcheckfree

De RAD Studio
Aller à : navigation, rechercher

Remonter à alloc.h - Index


Header File

alloc.h

Category

Memory Routines

Prototype

int heapcheckfree(unsigned int fillvalue);

Description

Checks the free blocks on the heap for a constant value.

Return Value

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

_BADVALUE

A value other than the fill value was found

_HEAPCORRUPT

Heap has been corrupted

_HEAPEMPTY

No heap

_HEAPOK

Heap is accurate

Example

#include <stdio.h>
#include <alloc.h>
#include <mem.h>

#define NUM_PTRS  10
#define NUM_BYTES 16

int main(void)
{
  char *array[ NUM_PTRS ];
  int i;
  int 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( heapfillfree( 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( "Bad value in free space.\n" );
             return 1;
        default:
             printf( "Unknown error.\n" );
             return 1;
     }

  printf( "Test successful.\n" );
  return 0;
}


Portability

POSIX Win32 ANSI C ANSI C++

+