[Qt-interest] SIGSEGV when assigning a QByteArray

Bo Thorsen bo at fioniasoftware.dk
Mon Sep 6 08:47:18 CEST 2010


Den 03-09-2010 18:37, Josiah Bryan skrev:
> gdb reports that after a ton of iterations, all of a sudden QByteArray
> crashes inside an "=" assignment:
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1208985328 (LWP 12157)]
> QByteArray::operator= (this=0xbf8cc1bc, other=@0xb5421f70) at
> ../../include/QtCore/../../src/corelib/arch/qatomic_i386.h:120
> 120     ../../include/QtCore/../../src/corelib/arch/qatomic_i386.h: No
> such file or directory.
>           in ../../include/QtCore/../../src/corelib/arch/qatomic_i386.h
> (gdb) bt
> #0  QByteArray::operator= (this=0xbf8cc1bc, other=@0xb5421f70) at
> ../../include/QtCore/../../src/corelib/arch/qatomic_i386.h:120
> #1  0x0806a404 in VideoSource::frame (this=0xb5421f10) at VideoFrame.h:80
> ...
>
> For reference, the VideoFrame class referred to is here:
> http://code.google.com/p/dviz/source/browse/trunk/src/livemix/VideoFrame.h#80
>
>
> I'm not doing anything special with the bytearray - just assigning it
> and passing it around. It originates in one thread, then is passed to a
> second thread for rendering when requested. It's not a pointer, so I'm
> expecting Qt to automatically take care of memory management and not
> delete till all instances are discarded.
>
> This crash is repeatable - but only if I let my program run a long time
> (20-30 minutes or more) - by run, I mean just show a video feed on the
> screen and let it sit there for 20-30 minutes, rendering the feed. So,
> reproducable - yes, but only after a looong time. It is, at least the
> last two crashes, always crashed at a same spot, and the same backtrace.
>
> Any ideas on what could be happening or what I can do to debug further?
>
> (And no, valgrind is no help - It's been running in valgrind for over an
> hour now and still no sign of a crash! But crashes in gdb every time
> within 30 minutes or so...)

This can only be a guess. However, I'm willing to bet you that this is 
the reason.

First, that it only happens rarely is a certain sign you have a race 
condition in your thread code. And the crash suggests to me that 
something have deleted the bytearray object.

When copying implicitly shared objects, you pretty much only copy an 
internal pointer. So it's very fast. And when the last object holding 
the internal pointer is deleted, so is the contents. I'll bet you that 
the race condition is somewhere in the code that copies the objects over 
to other threads. When the object is handed over to the other thread, it 
is deleted in the originating thread before it's "accepted" in the 
receiving thread.

You should switch to using pointers instead, and do your own memory 
management on them.

I hope this helps.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list