ubuntu@VM-0-15-ubuntu:~$ man mtraceMTRACE(1) Linux user manual MTRACE(1)NAME mtrace - interpret the malloc trace logSYNOPSIS mtrace [option]... [binary] mtracedataDESCRIPTION mtrace is a Perl script used to interpret and provide human readable output of the trace log contained in the file mtracedata, whose contents were produced by mtrace(3). If binary is provided, the output of mtrace also contains the source file name with line number information for problem locations (assuming that binary was compiled with debugging information). For more information about the mtrace(3) function and mtrace script usage, see mtrace(3).
ubuntu@VM-0-15-ubuntu:~$ man mtrace(3)-bash: syntax error near unexpected token `('ubuntu@VM-0-15-ubuntu:~$
其实,正确的姿势如下:
ubuntu@VM-0-15-ubuntu:~$ man 3 mtraceMTRACE(3) Linux Programmer's Manual MTRACE(3)NAME mtrace, muntrace - malloc tracingSYNOPSIS #include <mcheck.h> void mtrace(void); void muntrace(void);DESCRIPTION The mtrace() function installs hook functions for the memory-allocation functions (malloc(3), realloc(3) memalign(3), free(3)). These hook functions record tracing information about memory allocation and deal[m location. The tracing information can be used to discover memory leaks and attempts to free nonallocated memory in a program. The muntrace() function disables the hook functions installed by mtrace(), so that tracing information is no longer recorded for the memory-allocation functions. If no hook functions were successfully installed by mtrace(), muntrace() does nothing. When mtrace() is called, it checks the value of the environment variable MALLOC_TRACE, which should con[m tain the pathname of a file in which the tracing information is to be recorded. If the pathname is suc[m cessfully opened, it is truncated to zero length. If MALLOC_TRACE is not set, or the pathname it specifies is invalid or not writable, then no hook func[m tions are installed, and mtrace() has no effect. In set-user-ID and set-group-ID programs, MALLOC_TRACE is ignored, and mtrace() has no effect.
ubuntu@VM-0-15-ubuntu:~$ mtrace a.out test.log- 0x00000000018ab010 Free 3 was never alloc'd 0x7fb41725fe9d- 0x00000000018ab0e0 Free 4 was never alloc'd 0x7fb41732a91f- 0x00000000018ab100 Free 5 was never alloc'd 0x7fb41739a23cMemory not freed:----------------- Address Size Caller0x00000000018ab570 0x8 at /home/ubuntu/test.c:8ubuntu@VM-0-15-ubuntu:~$