Everything

free [V1.02 or later]


Releases memory.

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

void __far free(void __near *ptr);

[Description]

This function releases the area indicated by ptr. If ptr is a null pointer, no processing is performed. In addition to that, if ptr is not an area allocated by calloc, malloc, or realloc, or ptr has already been released by free or realloc, operation is not guaranteed.

 

[Professional Edition only] [V1.03 or later]

When using a malloc library for the security facility, the __heap_chk_fail function is called when one of the following operations is performed.

-

The pointer to an area other than that allocated by calloc, malloc, or realloc is passed to free or realloc.

-

The pointer to an area released by free is passed again to free or realloc.

-

After calloc, malloc, or realloc, a value is written to an address outside the allocated area (within two bytes before and after the allocated area) and the pointer to that area is passed to free or realloc.

 

The __heap_chk_fail function needs to be defined by the user and it describes the processing to be executed when an error occurs in management of dynamic memory.

Note the following points when defining the __heap_chk_fail function.

-

The __heap_chk_fail function should be a far function whose return value and parameter type should be the void type.
void __far __heap_chk_fail(void);

-

Do not define the __heap_chk_fail function as static.

-

Corruption of heap memory area should not be detected recursively in the __heap_chk_fail function.

 

The calloc, malloc, and realloc functions for the security facility allocate four extra bytes before and after each allocated area for the purpose of detecting writing to addresses outside the allocated area. This consumes more heap memory area than with the usual functions.