Configuring librcheck for Memory Analysis

Updated: April 19, 2023

To start a program that uses librcheck and can send heap trace data to the Memory Analysis tool in the QNX Momentics IDE, you must preload the librcheck.so library and set other environment variables to configure Memory Analysis options. Here, we give examples of running with minimal settings.

librcheck environment variables

The librcheck environment variables and their corresponding UI options in the IDE (if any) are:
Environment variable Where to find in Memory Analysis UI What option to set Additional information
LD_PRELOAD=librcheck.so Advanced Settings Runtime library The library file is librcheck.so.
MALLOC_ACTION=number Memory Errors When an error is detected Set the error-handling action: 0 to ignore, 1 to abort, 2 to exit, 3 to core, 4 to stop.
MALLOC_CKACCESS=0|1 Memory Errors Verify parameters in string and memory functions Turn boundary checking on or off for string and memory functions.
MALLOC_CKALLOC=0|1 Memory Errors Enable check on realloc()/free() argument Enable or disable the checking that the pointers passed to realloc() and free() point to memory that the allocator manages.
MALLOC_CKBOUNDS=0|1 Memory Errors Enable bounds checking (where possible) Turn fill-area boundary checking on or off.
MALLOC_CKCHAIN=0|1 Memory Errors Perform a full heap integrity check on every allocation or deallocation Turn full-chain checking on or off.
MALLOC_CTHREAD=0|1|2 Advanced Settings Create control thread Don't start a control thread (0), or do start the thread and allow the IDE to send commands to the application either through /dev/rcheck (1) or using signals (2).
MALLOC_CTRL_FILE=file N/A N/A Specify a file for the control command (to use with the control signal). The filename can contain ${pid} to add the process ID, with $ quoted if running from the shell.
MALLOC_CTRL_SIG=sigs N/A N/A Override the default signals (e.g., "control:41,leaks:42,start:44,stop:43,marker:45").
MALLOC_DUMP_LEAKS=0|1 Memory Errors Perform leak check when process exits Enable or disable the dumping of leaks on exit.
MALLOC_EVENTBTDEPTH=number Memory Tracing Limit back-trace depth to Set the depth of allocation backtraces to a specific number. The default is 5.
MALLOC_EVENTFILE=file Advanced Settings Target output file or device Redirect the event output to a file. The filename can contain ${pid} to add the process ID. Use a hyphen (-) to redirect the output to standard output (the default).
MALLOC_FILE=file Advanced Settings Target output file or device Redirect the event and trace output to a file. The filename can contain ${pid} to add the process ID, with $ quoted if running from the shell. Use a hyphen (-) to redirect the output to standard output (the default).
MALLOC_HANDLE_SIGNALS=0|1 N/A N/A Whether to install handlers for the SIGSEGV, SIGBUS, SIGILL, and SIGFPE signals.
MALLOC_HELP=1 N/A N/A Print a list of used environment variables.
MALLOC_SAMPLING=millis N/A N/A Run sampling thread to produce heap statistics every millis milliseconds.
MALLOC_START_TRACING=0|1 Memory Tracing Enable memory allocation or deallocation tracing Whether to automatically start tracing memory when the program starts.
MALLOC_STAT_BINS=bin1,bin2,... Memory Snapshots Bin counters (comma separated) Set custom bins for the allocation ranges for which to collect statistics.
MALLOC_TRACEBTDEPTH=number Memory Tracing Limit back-trace depth to Set the allocation backtraces depth to a specific number.
MALLOC_TRACEMAX=number Memory Tracing Maximum allocation to trace Only trace allocations of <= number of bytes.
MALLOC_TRACEMIN=number Memory Tracing Minimum allocation to trace Only trace allocations of >= number of bytes.
MALLOC_TRUNCATE=0|1 N/A N/A Whether to truncate the output files.
MALLOC_USE_CACHE=number N/A N/A Specify the size of the pointer cache; the value must be a power of 2 from 0 through 2048. Set to 0 to disable optimization. The default is 32.
MALLOC_VERBOSE=0|1 Advanced Settings Show debug output on console A value of 1 makes the library send debug information to standard error.