Click to See Complete Forum and Search --> : coredump in malloc (C)
Jmlt
February 12th, 2002, 08:24 AM
Hi all, i know it's not really a C place, but i need a hand...
In a multithreaded application in C under Unix (solaris5.8), I have sometimes a coredump in malloc (!).
Does someone knows how a segfault can be produced in a malloc ?
All ideas and help will be appreciated...
Thanks you in advance.
JeanMarc LE TOUX
"Computers are like air conditioners. They don't work when Windows are open." ;)
<b>JeanMarc LE TOUX</b>
"You may say i'm a dreamer, but i'm not the only one" J.L.
dede
February 12th, 2002, 08:55 AM
So, most case of a segmentation fault is a violation access memory !!
so can u give your malloc instruction ?
Jmlt
February 12th, 2002, 09:01 AM
I know that... The problem is that each execution won't fail at the same moment...
Last execution failed on a malloc(1024) !
All my test with purify or the dmalloc (www.dmalloc.org) librairie don't provide me any help, 'cause they didn't detect any bad writing, or bad access to memory...
<b>JeanMarc LE TOUX</b>
"You may say i'm a dreamer, but i'm not the only one" J.L.
Paul McKenzie
February 12th, 2002, 11:03 AM
Do you expect an answer without showing some code?
You are overwriting memory somewhere, or you're not releasing the memory. If your code is small enough *and* compilable, then post it.
Regards,
Paul McKenzie
thew
February 12th, 2002, 04:58 PM
Yep Paul is right.
If you're blowing up on a malloc call and it's not totally obvious to you either 1) you're overlooking something stupid ( which intelegent people do all the time ) or your walking on memory somewhere earlier in your program and the os takes the malloc line as a nice place to caugh up the fur ball which you've actually been choaking on for some time.
If I were you
1) I'd check my threads and make sure no two threads were using the same memory/variable without a semphore or mutex as a trafic cop.
2) I'd check very carefully if I'm walking on memory someplace else. Static array? Pointers? Strings? all should be examined carefully.. Backwards sometimes helps...
3) Worst case I'd comment out blocks of my code and see if I can get back to a base set that doesn't blow up. Then I'd slowly reintroduce code trying to isolate where I'm actually having the issue.
4) I'd publish my code as paul suggests and see if I can get a few more eyes on the issue. If it's small enough to actually allow for such a luxury.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.