When testing the example given in the mtrace(3) man page,
no data are generated:
$ cat t_mtrace.c
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
mtrace();
for (unsigned int j = 0; j < 2; j++)
malloc(100); /* Never freed--a memory leak */
calloc(16, 16); /* Never freed--a memory leak */
exit(EXIT_SUCCESS);
}
$ cc -g t_mtrace.c -o t_mtrace
t_mtrace.c: In function ‘main’:
t_mtrace.c:11:5: warning: ignoring return value of ‘malloc’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | malloc(100); /* Never freed--a memory leak */
| ^~~~~~~~~~~
t_mtrace.c:13:3: warning: ignoring return value of ‘calloc’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | calloc(16, 16); /* Never freed--a memory leak */
| ^~~~~~~~~~~~~~
$ export MALLOC_TRACE=/tmp/t
$ ./t_mtrace
$ mtrace ./t_mtrace $MALLOC_TRACE
Cannot open mtrace data file at /bin/mtrace line 152, <locs> line 4.
$ ls $MALLOC_TRACE
ls: cannot access '/tmp/t': No such file or directory