June 2017
Intermediate to advanced
478 pages
13h 14m
English
mtrace is a component of glibc that traces calls to malloc, free, and related functions, and identifies areas of memory not freed when the program exits. You need to call the mtrace() function from within the program to begin tracing and then at runtime, write a path name to the MALLOC_TRACE environment variable in which the trace information is written. If MALLOC_TRACE does not exist or if the file cannot be opened, the mtrace hooks are not installed. While the trace information is written in ASCII, it is usual to use the mtrace command to view it.
Here is an example:
#include <mcheck.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { int j; mtrace(); for (j = 0; j < 2; j++) malloc(100); /* Never freed:a ...Read now
Unlock full access