Re: Memory leak!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sep 11, 2009, at 12:30 AM, Brian McGrew wrote:

Help, I?ve got a memory leak and it?s spilling all over the floor!

LOL, I wish it was that simple... I?ve got several appliactions that all share the same ?common? memory and all rely on about 75 shared libraries out of my tree. Somewhere I?ve got a memory leak and I have no idea where to find it. I?m currently using gcc-4.1.3 on CentOS_x86-64 but the problem is
exhibited on Fedora Core 5 with gcc-4.1.0

This is the first time I?ve ever been faced with finding a memory leak and I?ve got no idea where to start or how to do it. Please help! I?ve googled
and found lots of stuff, but nothing that looks like it?s directly
applicable to finding a memory leak.  Also, I?m restricted to whatever
software is in the open, I have no commerical tools for this.

Someone, PLEASE point me in the right direction!

Thanks,

-brian

Hi, Brian!

Do you have access to the source code for those shared libraries? That would make things a lot easier.

Especially if you do have access, and if you don't want to use Valgrind as Philip suggested, here's what I might suggest:

In GDB, set breakpoints at malloc and calloc.
Every time you hit malloc or calloc:
  Get the stack trace ("backtrace"--"bt").
Find the call to malloc or calloc in the source if you have it available.
  Write some reference to the source line down in a (text) list.
  Find the corresponding call to free.
  Take the malloc or calloc call reference off your list.

When you're finished, you should have a list of calls to malloc or calloc that never got corresponding calls to free.

If the allocation is in a loop, there has to be a deallocation in a loop with the same number of iterations, or some other way of making sure the number of calls to free is the same. So your notations on your list should represent the number of iterations.

If the allocation is in a recursive call, it's harder to track, but the same principle would apply: compute the number of calls, and make sure that free is called the same number of times.

Best wishes,
Amittai

Amittai Aviram
Graduate Student in Computer Science
Yale University
646 483 2639
amittai.aviram@xxxxxxxx
http://www.amittai.com




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux