ISO free tools to debug malloc/free bugs

K

kj

For me, the hardest bugs to figure out have to do with malloc and/or
free, because such a bug usually manifests itself as a seg fault
happening at a place in the code that, AFAICT, can be totally
unrelated to the code responsible for the bug.

I know that there are commercial tools to help with such bugs, but
I work at an academic lab on a shoestring, so we make do with open
source tools unless it is absolutely unavoidable to spring for the
non-free stuff.

Are there any free tools to help tracking such bugs? FWIW, I use
gcc-2.95.

Thanks!

kj
 
D

Daniel Vallstrom

kj said:
For me, the hardest bugs to figure out have to do with malloc and/or
free, because such a bug usually manifests itself as a seg fault
happening at a place in the code that, AFAICT, can be totally
unrelated to the code responsible for the bug.

I know that there are commercial tools to help with such bugs, but
I work at an academic lab on a shoestring, so we make do with open
source tools unless it is absolutely unavoidable to spring for the
non-free stuff.

Are there any free tools to help tracking such bugs?

Have a look at the excellent Valgrind. It's doubly free too.

Daniel Vallstrom
 
C

Chris Croughton

For me, the hardest bugs to figure out have to do with malloc and/or
free, because such a bug usually manifests itself as a seg fault
happening at a place in the code that, AFAICT, can be totally
unrelated to the code responsible for the bug.

I know that there are commercial tools to help with such bugs, but
I work at an academic lab on a shoestring, so we make do with open
source tools unless it is absolutely unavoidable to spring for the
non-free stuff.

Are there any free tools to help tracking such bugs? FWIW, I use
gcc-2.95.

Yes, dmalloc (http://dmalloc.com/). Some Linux systems have it already
compiled as a package (Debian, for instance).

The author does ask (but doesn't insist) that it you find it useful you
make a donation (the actual software is released under a very permissive
licence). I found it useful (incredibly so; after a week of trying to
find a problem which caused free() to crash -- it was obviously
something writing somewhere it shouldn't, but I couldn't see what -- I
used dmalloc and it trapped the area being overwritten, I looked at the
bad values in the guard area and it was obvious what did it)...

Chris C
 
C

CBFalconer

kj said:
For me, the hardest bugs to figure out have to do with malloc and/or
free, because such a bug usually manifests itself as a seg fault
happening at a place in the code that, AFAICT, can be totally
unrelated to the code responsible for the bug.

I know that there are commercial tools to help with such bugs, but
I work at an academic lab on a shoestring, so we make do with open
source tools unless it is absolutely unavoidable to spring for the
non-free stuff.

Are there any free tools to help tracking such bugs? FWIW, I use
gcc-2.95.

If you use DJGPP (which you can under most editions of Windows or
MsDos) you can use my nmalloc package (which was written for DJGPP,
but has not yet been incorporated). It includes a debugging
package, and info documentation entries for it all. You can find
it at:

<http://cbfalconer.home.att.net/download/nmalloc.zip>

Ignore the memalign garbage in the package, that is incomplete. It
might function with other systems than DJGPP, but that is a
separate matter, and no guarantees.
 
J

Jonathan Bartlett

kj said:
For me, the hardest bugs to figure out have to do with malloc and/or
free, because such a bug usually manifests itself as a seg fault
happening at a place in the code that, AFAICT, can be totally
unrelated to the code responsible for the bug.

You can use a garbage collector like Boehm. It also does malloc debugging.

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

Also, you might be interested in my DeveloperWorks article on memory
management:

http://www-106.ibm.com/developerworks/linux/library/l-memory/

It has a lot of interesting ideas and good resources.

Jon
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top