Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LI-14190 - Looking for best memory leak procedure for linux

Posted on 2010-11-19
12
Medium Priority
?
558 Views
Last Modified: 2012-05-10
We are using gcc --version 4.1.2.20080704 (Red Hat 4.1.2-48).  We have memory leaks that rival the water supply lines in Boston.  

We have considered making our own "new" and "delete" wrapper functions to track where this is happening, but prefer to use gdb/sdb or something else already written that would let us discover where we are not deleting objects, etc.  We are only somewhat familiar with gdb/sdb, but willing to try anything.

Anyone have suggestions/sites we can go to, to find a good procedure for finding these leaks?

Thanks!
0
Comment
Question by:dgintz1217
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 8

Accepted Solution

by:
Anthony2000 earned 2000 total points
ID: 34175367
Have you thought of using something like Valgrind?

http://valgrind.org/docs/manual/quick-start.html#quick-start.intro
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 34175740
Another technique I used in my daemon:

from in my app, I read the /proc/<my process id>/mem (I don't remember the name of the entry) it contained the amount of memory my application was consuming.

I wrote a function that would read this value and I kept a static copy of it. Later in my code, I would call call a function I called CheckMemory(). This function compared the current /proc/<my process id>mem value of my memory consumption. if it increased/decreased, I wrote to syslog. I then ran Tail on the syslog output and watched my memory change.  The CheckMemory function was really a macro that passed the __LINE__ and __FILE__ information to the log. I could then place these instrategic places in my code.

I only suggest this because it is fairly easy to do. I might even be able to find the guts of my program and share them with you. I just have to look for it.

The benefit of using this is that you don't have to learn another tool. I was able to quickly find the areas of my program that were leaking memory. In many cases it was not my New() function that was causing the problem, but, rather places where I forgot to call the close function on an open handle, etc.

0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 34186589
I hacked Tcl's memory debug package so it could be used stand_alone (without Tcl) for just this purpose.
You need to ensure that every single module which uses malloc / realloc / free has the ckalloc.h header. (If you use calloc, you'll have to write your own macro (using mallocmemset)).
At any time you like, you can call Tcl_DumpActiveMemory to get a map of all allocated memory areas with file and line number where they were allocated. You should spot the leaks fairly quickly. Good luck!
ckalloc.h
tclCkalloc.c
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Expert Comment

by:Duncan Roe
ID: 34186613
You also have to build with -DTCL_MEM_DEBUG
0
 

Author Comment

by:dgintz1217
ID: 34191033
This is c++, so its "new" and "delete".  duncan, does your solution still apply?

Thanks!
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 34191948
Sorry no. I missed that you mentioned "new" and "delete" in your original Q. These call constructors / destructors - way out of the scope of ckalloc
0
 

Author Comment

by:dgintz1217
ID: 34320288
So I will try the valgrind then at this point.
0
 

Author Comment

by:dgintz1217
ID: 34764904
Will I still have access to the question and answers in my account even if the question gets closed out?
Thanks!
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 34765436
Yes - it'll be there. You can also bookmark it by touching "save"
0
 

Author Comment

by:dgintz1217
ID: 34765577
ok, we will let it close if I don't mark accept on something before 2/5.
THanks very much!
Richard
0
 
LVL 40

Expert Comment

by:evilrix
ID: 34824221
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question