Home > Back-end >  About mtrace debugging memory leak problem
About mtrace debugging memory leak problem

Time:05-28

Learning under Linux mtrace memory leak problem encountered in the process of adjustment, the code is as follows:
 # include & lt; stdio.h> 
#include
#include

Void mtrace_malloc * * p (int);

Int main ()
{
The setenv (" MALLOC_TRACE ", "/var/TMP/mtraceOutput", 1);

Mtrace ();
Int * p=NULL;
Mtrace_malloc (& amp; P);
Printf (" addr in the main: % p \ n ", p);
//muntrace ();

return 0;
}

Void mtrace_malloc (int * * p)
{
Printf (" addr in func: % p \ n ", * p).
}

Terminal output is:
 addr in func: (nil) 
Addr in the main: (nil)

Check the mtrace log information:
=Start 
@/lib/x86_64 - - the gnu/Linux libc. So. 6: (_IO_file_doallocate + 0 x94) x7f9818d7fe84 [0] + 0 x20838d0 0 x400
@/lib/x86_64 - - the gnu/Linux libc. So. 6: x7f9818e9683d [0] - 0 x20832a0
@/lib/x86_64 - - the gnu/Linux libc. So. 6: (tdestroy + 0 x36) x7f9818e18996 [0] - 0 x2083490
@/lib/x86_64 - - the gnu/Linux libc. So. 6: x7f9818e96826 [0] - 0 x20834c0
@/lib/x86_64 - - the gnu/Linux libc. So. 6: x7f9818e9696c [0] - 0 x20838d0

Can see there are memory allocation (" + "in the first row) steps, held several different address of memory and subsequent release (" -") in the rest of the line
The above code is no malloc and allocate memory function

Ask why there will be a memory allocation in mtrace steps, multiple memory release what reason?

CodePudding user response:

 mtrace (); 

Have a look at how this function in the operation,

CodePudding user response:

Linux is not open source? See what _IO_file_doallocate function,
  • Related