On Sun, Mar 8, 2009 at 7:54 PM, Michael Robinson
<[email protected]>wrote:

> The code to empty out my linked list of lines is crashing.
>
> I'm having a heck of time finding this bug.  It only happens
> the third time I try to read a file.  Using backtrace in gdb
> tells me it is happening when I'm dumping the old list prior
> to loading fresh lines into it.  I get a sig abort and it is
> always crashing on a free command.


Sounds like a bad pointer.  This could be happening because you're calling
free on a previously free'd pointer.  Try setting your pointers to NULL on
creation and after you free them.  Then if you see yourself working with a
NULL pointer, more likely the C run-time will catch it, then you know you're
working with bad pointers.

You could/should also try enabling the run-time extended debugging for the C
run-time via the environment variable *MALLOC_CHECK_*:
http://linux.die.net/man/3/malloc

This IBM article has lots of cool little programs you can use:
http://www.ibm.com/developerworks/linux/library/l-debug/

Ultimately, I think your best bet for seeing the problem is valgrind:
http://valgrind.org/docs/manual/QuickStart.html



>
> I realize without putting my code up that people are going to
> have a hard time figuring this one out, though I wonder if
> anyone has any idea how this third times the charm thing
> is happening?


C is not a safe programming language.  Once you do something that is bad, or
"undefined", you cannot expect to know about it at all.  Consider yourself
lucky that it shows up consistently on the 3rd try.  Likely whatever you're
doing wrong is wrong on each attempt but due to the nature of the C language
and the kernel it doesn't manifest until you hammer on it.

As an experiment you could remove all calls to free and see if the bad
behavior goes away.  If it does, then it is very likely to be a resource
cleanup issue.

Good luck,
Jason
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to