home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.os.os2.programmer:4307 comp.lang.c:12491
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!sdd.hp.com!swrinde!gatech!news.ans.net!ans.net!db3l
- From: db3l@ans.net (David Bolen)
- Newsgroups: comp.os.os2.programmer,comp.lang.c
- Subject: Re: malloc causes a segmentation violation!?
- Message-ID: <1992Aug18.170550.66326@ans.net>
- Date: 18 Aug 92 13:07:04 GMT
- References: <1992Aug18.143135.6259@cc.tut.fi>
- Sender: news@ans.net (News Administrator)
- Organization: Advanced Network & Services, Inc. - Elmsford, NY
- Lines: 48
- In-Reply-To: mn87504@cs.tut.fi's message of Tue, 18 Aug 92 14: 31:35 GMT
-
- In article <1992Aug18.143135.6259@cc.tut.fi> mn87504@cs.tut.fi (Naatula Mika) writes:
-
- >Sometimes my program causes a segmentation fault. If I drive it with
- >CVP I can find out (from calls sequence) that the error was caused by
- >malloc. To be exact, malloc calls an internal(?) function named
- >_searchseg() that fails. Any ideas what this function might be?
- >
- >(...)
- >
- >My program uses a lot of dynamic memory allocation, but I am quite
- >sure that there is no bugs in my code. I have spent two days checking
- >out the memory allocation of this program.
-
- I'd go back and spend some more time looking. This very much sounds like
- something in your program used and errant pointer and trashed some of the
- memory control blocks used by the C compiler's memory allocation routines.
- The program only dies when you next try to do a malloc and the C compiler
- needs to scan for free space - the corrupted internal pointers cause the
- trap.
-
- Dynamic memory problems are very subtle and hard to track. Two days might
- only be a fraction of the time necessary to locate such a bug - I know I've
- spent a significantly longer time tracking down such bugs in the past.
-
- Some things that can help is to dump debugging output for every allocation
- and free operation and ensure that everything matches. Also - there are
- some libraries around (I'm not positive where - maybe someone else can
- help?) that replace the standard allocation calls, and set up signature
- areas around the allocated memory to help you track down the piece of code
- that is munging the wrong memory.
-
- Alternatively, if you can somehow replicate a sequence of steps that causes
- the problem (not always possible), then you can scrutinize the code path
- that those steps take to see if you can find an uninitialized pointer, memory
- used after freeing, fencepost errors (ie: going 1 past the end of an array),
- etc..
-
- Probably not what you wanted to hear - but I think you'll probably find the
- root of this problem in your code somewhere...
-
- --
- -- David
- --
- /-----------------------------------------------------------------------\
- \ David Bolen \ Internet: db3l@ans.net /
- | Advanced Network & Services, Inc. \ Phone: (914) 789-5327 |
- / 100 Clearbrook Road, Elmsford, NY 10523 \ Fax: (914) 789-5310 \
- \-----------------------------------------------------------------------/
-