[Qt-interest] SIGSEGV with single-line gdb backtrace
Josiah Bryan
jbryan at productiveconcepts.com
Mon Sep 28 04:09:10 CEST 2009
Bill King wrote:
> Bill - thanks for the quick response.
>
>> helgrind isn't working (according to valgrind) in my current version of
>> valgrind. memcheck reports various lost memory, but no help finding a
>> SIGSEGV. In fact, the SIGSEGV didn't even occur during any valgrind
>> sessions I just ran, but the program *did* run very very slow. Which
>> leads me to believe that the SIGSEGV is being caused by some wierd
>> thread interaction.
>>
>> But how to you debug *that* beast?
>>
>> Thanks,
>> -josiah
>>
>>
>>
> The dreaded heisenbugs :) Update your valgrind if possible. There's a
> good chance that helgrind will catch it, now... Are you locking access
> to the variables that are likely to be accessed via another thread?
> Definately sounds like a race condition.
>
Alright, I narrowed it down using the good old-fashioned
"comment-out-lines-until-it-stops-crashing" method - and narrowed it
down to an obscure place in the destructor of my video decoder QThread:
At one point, I free all the libav stuff allocated, and one of the lines
does this:
av_free(m_av_frame);
Where m_av_frame was simply allocated earlier by "m_av_frame =
avcodec_alloc_frame();"
So, bottom line, somehow multithreading libavcodec et al is crashing a
QThread. The odd thing is, I've got two other calls to av_free for other
structures right above the free on m_av_frame - all are member variables
of the thread, none should be accessed by any other thread. Access to
the video frame is thru a mutex-locked buffer - the frame is converted
from the video's internal format to an rgb frame, a QImage allocated and
data copied into its bits(), and stuffed into the buffer with a mutex
lock. Any other thread (GUI thread) that wants a frame uses the buffer,
not even touching the decoder thread itself.
How, then, is this rotten piece of code causing a race condition and a
bloody SIGSEGV?
(BTW, I'm trying to update valgrind now - recompiling now. All the above
ranting was done based on source tracing. Any ideas from that? Or do I
still need to dredge up valgrind?)
Thanks,
-josiah
More information about the Qt-interest-old
mailing list