[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

General Programming Concepts:
Writing and Debugging Programs

Malloc Report

Malloc Error Reporting provides an optional error reporting and detection extension to the malloc subsystem. Information on errors that occurred in the malloc environment will be reported and actions can be performed if specified.

Malloc Error Reporting is not enabled by default, but can be enabled and configured prior to process startup through the MALLOCDEBUG environment variable. All errors located in the malloc subsystem are output to standard error, along with detailed information.

Malloc Error Reporting is not available for applications using User-Defined Malloc.

Malloc Report allows the user to provide a function that the malloc subsytem will call when it encounters an error. Before returning, Malloc Report calls the user-provided function.

A global function pointer is available for use by the user. In the code, the following function pointer should be set to the user's function:

extern void (*malloc_err_function)(int, ...)

The user provided function must set the following:

void malloc_err_function(int, ...)

For example, the following code must be inserted into the user's application:

malloc_err_function = &abort_sub

Check Arena

If the Default Allocator is enabled, you can check the structures that contain the free blocks before every allocation request is processed. This option will ensure that the arena is not corrupted. Also, the arena will also be checked when an error occurs.

For Default Malloc, the checkarena option checks for NULL pointers in the free tree or pointers that do not fall within a certain range. If an invalid pointer is encountered during the descent of the tree, the program might perform a core dump depending on the value of the invalid address.

The checkarena option is not available for applications using the malloc 3.1 allocation policy or User-Defined Malloc.

Enabling Error Reporting

Error reporting is not enabled by default, but is enabled and configured by setting the MALLOCDEBUG environment variable as follows:

MALLOCDEBUG=verbose

To enable a check of the arena before allocation request is processed or when an error occurs, set the MALLOCDEBUG environment variable to the following:

MALLOCDEBUG=checkarena

More than one option can be specified in any order, as long as they are comma-separated, as in the following example:

MALLOCDEBUG=checkarena,verbose

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]