memory leak

H

hari

A memory leak occurs when memory is allocated in a program and we
forget to deallocate and it is never returned to the operating
system, even though the program does not use the memory any longer.

Usually to finding memory leaks, i use valgrind tool. But how to find
those memory leaks in a C program without using valgrind?

Thanks in advance.
 
K

Karthik

In



Self-logging.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within

Or if you use gdb, "info leaks" would give u some useful information
on memory leaks without having to instrument the binary.
 
G

Gene

A memory leak occurs when memory is allocated in a program and we
forget to deallocate  and it is never returned to the operating
system, even though the program does not use the memory any longer.

Usually to finding memory leaks, i use valgrind tool. But how to find
those memory leaks in a C program without using valgrind?

Thanks in advance.

It is not very hard to replace malloc() with a routine that calls the
system malloc() and logs the returned pointer in a hash table before
returning it. Similarly replace free() with a version that deletes
the hash table entry and calls system free(). (Of course free()ing a
pointer not in the hash table is another kind of error.) As needed,
print a report of currently allocated blocks using the hash table. Of
course you are re-implementing valgrind, but I assume you are asking
because you have an environment where it's not available.

If you are using Microsoft compilers, the debugging library provides
some reasonable (not terrific) leak detection options. Check the
documentation.

I believe the Boehm Conservative Garbage Collector will also detect
leaks in one of its many configurations.
 
M

Mark

Karthik said:
Or if you use gdb, "info leaks" would give u some useful information
on memory leaks without having to instrument the binary.

[OT] My 'gdb-6.5' doesn't have sych facility. What version did it appear in?
[/OT]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top