Middleware, development tools, realtime operating system
software and services for superior embedded design


Home
QNX Community Resources
QNX Documentation Library
mallopt

mallopt

QNX Software Systems
Developer Resources
Blogs
Board support packages
Foundry27 projects
Forums
Hardware support listing
Online video tutorials
Product documentation
Technical Articles

mallopt()

Control the extra checking for memory allocation

Synopsis:

#include <malloc.h>

int mallopt( int cmd,
             int value );

Arguments:

cmd
Options used to enable additional checks in the library.
  • MALLOC_CKACCESS
  • MALLOC_FILLAREA
  • MALLOC_CKCHAIN
  • MALLOC_VERIFY
  • MALLOC_FATAL
  • MALLOC_WARN

See the Description section for more details.

value
A value corresponding to the command; see below:

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mallopt() function controls the extra checking of memory allocation.

Options used to enable additional checks in the library include:

MALLOC_CKACCESS
Turn on (or off) boundary checking for memory and string operations.
Environment variable: MALLOC_CKACCESS.

The value argument can be:

  • zero to disable the checking
  • nonzero to enable it.
MALLOC_FILLAREA
Turn on (or off) fill-area boundary checking.
Environment variable: MALLOC_FILLAREA.

The value argument can be:

  • zero to disable the checking
  • nonzero to enable it.
MALLOC_CKCHAIN
Enable (or disable) full-chain checking. For each of the above options, an integer argument value of one indicates that the given type of checking should be enabled from that point onward.
Environment variable: MALLOC_CKCHAIN.

The value argument can be:

  • zero to disable the checking
  • nonzero to enable it.
MALLOC_VERIFY
Perform a chain check. If an error is found, perform error handling. The value argument is currently ignored; pass 1 for it.
MALLOC_FATAL
Specify the malloc fatal handler.
Environment variable: MALLOC_FATAL.

Use one of the following for the value arguments:

Symbolic name Value Description
M_HANDLE_IGNORE 0 Cause the program to dump a core file.
M_HANDLE_ABORT 1 Terminate execution with a call to abort()
M_HANDLE_ABORT 2 Exit immediately
M_HANDLE_CORE 3 Cause the program to dump a core file
M_HANDLE_SIGNAL 4 Stop the program when this error occurs
MALLOC_WARN
Specify the malloc warning handler. The values are similar to MALLOC_FATAL; see above.
Environment variable: MALLOC_WARN.

For details, see "Controlling the level of checking" in the Heap Analysis: Making Memory Errors a Thing of the Past chapter of the Neutrino Programmer's Guide.


Note: See the Heap Analysis: Making Memory Errors a Thing of the Past chapter of the Neutrino Programmer's Guide.

Returns:

0 on success, or -1 if an error occurs (errno is set).

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

calloc(), free(), mallinfo(), malloc(), realloc()

Heap Analysis: Making Memory Errors a Thing of the Past chapter of the Neutrino Programmer's Guide