<s>
mtrace	B-Application
is	O
the	O
memory	B-General_Concept
debugger	I-General_Concept
included	O
in	O
the	O
GNU	B-Language
C	I-Language
Library	I-Language
.	I-Language
</s>
<s>
Note	O
that	O
mtrace	B-Application
tool	O
works	O
only	O
with	O
single	O
threaded	O
applications	O
.	O
</s>
<s>
One	O
thread	O
could	O
temporarily	O
remove	O
the	O
hook	O
while	O
another	O
thread	O
could	O
malloc	B-Language
memory	O
at	O
the	O
sametime	O
leading	O
to	O
missed	O
allocations	O
in	O
a	O
multithreaded	O
application	O
!	O
</s>
<s>
The	O
function	O
mtrace	B-Application
installs	O
handlers	O
for	O
malloc	B-Language
,	O
realloc	B-Language
and	O
free	O
;	O
the	O
function	O
muntrace	O
disables	O
these	O
handlers	O
.	O
</s>
<s>
void	O
mtrace(void )	O
;	O
</s>
<s>
A	O
perl	B-Language
script	O
called	O
mtrace	B-Application
,	O
not	O
to	O
be	O
confused	O
with	O
the	O
function	O
of	O
the	O
same	O
name	O
,	O
is	O
also	O
distributed	O
with	O
the	O
GNU	B-Language
C	I-Language
Library	I-Language
;	O
the	O
script	O
parses	O
through	O
the	O
output	O
file	O
and	O
reports	O
all	O
allocations	O
that	O
were	O
not	O
freed	O
.	O
</s>
<s>
In	O
Bourne	O
Shell-compatible	O
shells	O
,	O
like	O
Bash	B-Operating_System
,	O
the	O
command	O
is	O
as	O
follows	O
:	O
</s>
<s>
This	O
is	O
done	O
,	O
for	O
example	O
,	O
by	O
adding	O
the	O
following	O
line	O
to	O
the	O
top	O
of	O
a	O
C	B-Language
or	O
C++	B-Language
file	O
,	O
as	O
shown	O
below	O
:	O
</s>
<s>
Call	O
the	O
function	O
mtrace( )	O
before	O
you	O
start	O
allocating	O
memory	O
.	O
</s>
<s>
It	O
is	O
usually	O
easiest	O
to	O
call	O
mtrace( )	O
at	O
the	O
very	O
beginning	O
of	O
the	O
main( )	O
function	O
:	O
</s>
<s>
In	O
GCC	O
on	O
Linux	O
,	O
this	O
can	O
be	O
done	O
using	O
the	O
following	O
commands	O
for	O
a	O
C	B-Language
program	I-Language
:	O
</s>
<s>
Most	O
Linux	O
machines	O
come	O
with	O
a	O
console	O
command	O
called	O
mtrace	B-Application
,	O
that	O
converts	O
the	O
computer	O
readable	O
format	O
into	O
human-readable	O
text	O
as	O
shown	O
below	O
.	O
</s>
<s>
If	O
you	O
do	O
not	O
have	O
access	O
to	O
this	O
console	O
command	O
,	O
there	O
is	O
a	O
Perl	B-Language
script	O
,	O
of	O
the	O
same	O
name	O
,	O
that	O
can	O
be	O
downloaded	O
to	O
accomplish	O
the	O
same	O
task	O
.	O
</s>
<s>
The	O
mtrace	B-Application
syntax	O
is	O
as	O
follows	O
:	O
</s>
<s>
mtrace	B-Application
can	O
be	O
used	O
with	O
parallel	O
computing	O
but	O
one	O
process	O
at	O
a	O
time	O
,	O
using	O
a	O
condition	O
on	O
the	O
rank	O
like	O
:	O
</s>
<s>
If	O
the	O
mtrace	B-Application
command	O
reports	O
“	O
No	O
Memory	O
Leaks	O
”	O
,	O
then	O
all	O
memory	O
that	O
was	O
allocated	O
in	O
the	O
last	O
execution	O
of	O
that	O
program	O
was	O
also	O
released	O
,	O
which	O
is	O
the	O
way	O
it	O
should	O
be	O
.	O
</s>
<s>
If	O
,	O
on	O
the	O
other	O
hand	O
,	O
mtrace	B-Application
gives	O
output	O
such	O
as	O
that	O
below	O
,	O
it	O
means	O
the	O
programmer	O
still	O
has	O
some	O
work	O
to	O
do	O
.	O
</s>
<s>
It	O
releases	O
memory	O
after	O
it	O
is	O
allocated	O
,	O
and	O
it	O
uses	O
mtrace	B-Application
to	O
notify	O
the	O
programmer	O
if	O
there	O
are	O
memory	O
leaks	O
.	O
</s>
