Operating System - HP-UX
1823308 Members
3699 Online
109653 Solutions
New Discussion юеВ

Re: malloc/free debugging in a C code!

 
SOLVED
Go to solution
Ravi Abrol
Occasional Advisor

malloc/free debugging in a C code!

Hi,
I have a multi-code C project running on HP V-Class machines using MPI. The code crashes for at some free() statements, althought the things i am trying to free() look fine under the totalview debugger i am using. For different problem sizes, it crashes at different free() locations. Can someone help me with this? Is there any tool available on HPUX to help me diagnose this problem?
I badly need this information as I have a few deadlines to meet. Thanks in advance!
Ravi
world needs a good debugger!
12 REPLIES 12
Deepak Extross
Honored Contributor

Re: malloc/free debugging in a C code!

Try Rational's Purify.
It's pretty good at detecting MLK (memory leaks) and FUM (Freeing unallocated memory)
http://www.rational.com/products/purify_unix/index.jsp
Steven Gillard_2
Honored Contributor

Re: malloc/free debugging in a C code!

Purify is also my recommendation, but if you want something free you might like to try this garbage collector from HP labs:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

It contains replacements for the malloc and free routines and can also be used as a leak detector.

Regards,
Steve
Deepak Extross
Honored Contributor

Re: malloc/free debugging in a C code!

well, u can get a free eval copy of Purify at
http://www.rational.com/tryit/evals/purifyunix_eval.jsp
Ravi Abrol
Occasional Advisor

Re: malloc/free debugging in a C code!

thanks deepak and steve,
i tried using purify, but it doesn't work with mpicc (multi-processor cc). the garbage collector is working with my code but it crashes my code at strange places. i will be trying it for the next few days to see how it goes. do you know of any other tools?
thanks,
ravi
world needs a good debugger!
Scott Van Kalken
Esteemed Contributor

Re: malloc/free debugging in a C code!

There is a memory tool available called electric fence. This is nowhere near as good as Purify. It's a freeware tool that I have used specifically to hunt down problems with malloc on HPUX.

Here's the skinny on it:

ElectricFence is a utility for C programming and
debugging. ElectricFence uses the virtual memory hardware of your
system to detect when software overruns malloc() buffer boundaries,
and/or to detect any accesses of memory released by
free(). ElectricFence will then stop the program on the first
instruction that caused a bounds violation and you can use your
favorite debugger to display the offending statement.

Install ElectricFence if you need a debugger to find malloc()
violations.


I'm not sure if it would work in a MPI environment.
Scott Van Kalken
Esteemed Contributor

Re: malloc/free debugging in a C code!

I also got this out of google


http://www.cs.colorado.edu/homes/zorn/public_html/MallocDebug.html


it's a neat overview of some tools.

Hope this helps


Scott.
Ravi Abrol
Occasional Advisor

Re: malloc/free debugging in a C code!

hi scott,
thanks for the list and the intro on electric fence. i will certainly try to use some of them to see if they can work with my C code in MPI environment on HPUX. i tried running my code in the AIX environment on an IBM SP machine (to which i have only limited access) and these memory problems didn't occur there.
thanks again!
ravi
world needs a good debugger!
Deepak Extross
Honored Contributor

Re: malloc/free debugging in a C code!

Gregory Fruth
Esteemed Contributor

Re: malloc/free debugging in a C code!

Maybe the mallinfo() and memorymap() functions
will be of some use.

HTH
Ravi Abrol
Occasional Advisor

Re: malloc/free debugging in a C code!

hi greg,
thanks! do you know how to use them or where i can find more information on how to use them!
ravi
world needs a good debugger!
Deepak Extross
Honored Contributor

Re: malloc/free debugging in a C code!

Ravi,
The man page for malloc itself has details on mallinfo() and memorymap().
Scott Van Kalken
Esteemed Contributor
Solution

Re: malloc/free debugging in a C code!

Ravi,

You wont see the same problems in AIX because AIX tends to clean up memory is deallocated but not freed.

We had a problem with an app ported from AIX to HPUX that had this problem.

We solved 90% of our memory problems by working on the theory that everywhere there was a memory allocation there should be a corresponding free.

Scott.