Re: program crashes *after* exit




"Jonathan Addleman" <jonathan.addleman@xxxxxxxxxxxxxx> wrote in message news:301fd$47c33096$4c0a9293$18720@xxxxxxxxxxxxxxxxxxxx
I'm writing a program that appears to work, except that I get a segfault
when the program exits. The code is all in C, running on linux. The
crash is intermittent though - most of the time it does give the
segfault, but maybe 1/10 of the time, it runs just fine, and every now
and then it freezes.

The crash seems to come after the end of the actual code - a gdb
backtrace looks like this:

Program received signal SIGSEGV, Segmentation fault.
0x0804e090 in ?? ()
(gdb) backtrace
#0 0x0804e090 in ?? ()
#1 0xb7ef7ff4 in ?? () from /usr/lib/debug/libc.so.6
#2 0xb7ef9140 in ?? () from /usr/lib/debug/libc.so.6
#3 0x0804e008 in ?? ()
#4 0xbf8b4f28 in ?? ()
#5 0xb7e2fde9 in *__GI___libc_free (mem=0x0) at malloc.c:3622
#6 0x08048c51 in _start ()


which doesn't really tell me a whole lot. When it's frozen, it says that
it's just sitting on the final line of the code (the curly brace closing
main).


<snip>


I had a look at http://c-faq.com/strangeprob/crashatexit.html which
seems to describe the problem that I'm having, but I don't see anything
on that page that might be causing it in my code.

Is there anything else that I can test that might help debug this issue?


IME, what most often causes this kind of thing is messing up somewhere with malloc'ed memory, such as writing past the end (or before the start) of a buffer, or accidentally freeing something multiple times.

valgrind output seems to imply that some 'phantom' code is being generated that is for whatever reason broken (to verify this would likely require looking at the assembler output).


maybe check that no stack-based buffers are being overflowed as well...

or such...



--
Jon-o Addleman
http://www.redowl.ca

.



Relevant Pages

  • Re: program crashes *after* exit
    ... when the program exits. ... The crash seems to come after the end of the actual code - a gdb ... backtrace looks like this: ... Program received signal SIGSEGV, Segmentation fault. ...
    (comp.programming)
  • Re: Office crashes in Snow Leopard.
    ... So far Word and Excel did crash. ... Generally, I open a saved file and when I try to edit it, the program exits and the error message appears. ...
    (microsoft.public.mac.office)
  • Re: OO compilers and efficiency
    ... > program exits. ... If you can't gaurantee this won't crash the machine, ...
    (comp.programming)
  • Re: program crashes *after* exit
    ... when the program exits. ... The code is all in C, running on linux. ... crash is intermittent though - most of the time it does give the ... The crash seems to come after the end of the actual code - a gdb ...
    (comp.programming)