Totally confusing segmentation violation



  • I have a problem which appears apparently randomly which is a SIGSEGV but the stack trace only has main() as a viewable level.

    The levels below main() of the stack are all grey and seem to terminate in a call to getenv. It happens when I make a change to my code and the change can be almost anything! I have to save my work after each small step just to make sure I don't have to back-track too far.
    There is a long list of function calls which are greyed out above the main() listing. The last call is to __GI_getenv(). When I run the code in gdb instead of the Qt environment, I see a stack trace with the following message

    Thread 1 "GenisysVoicesPa" received signal SIGSEGV, Segmentation fault.
    __GI_getenv (name=0x7fffee365b47 "_NO_FT_CACHE") at getenv.c:84
    84 getenv.c: No such file or directory.
    (gdb)

    On another occasion the string passed was "US_REGION" neither of these strings are in my code.
    I have no idea why this segmentation violation pops up and it seems to happen randomly in the course of my work.

    Sometimes if I go to a previous version that worked, and I return to the new version that didn't, the new version starts to work! So that seems to imply an environment issue but I'm not changing anything (that I know of) in my environment. If I had hair I'd be pulling it out!
    Can anyone help? please!
    Thank you,
    Michael Toth

    Here is the complete stack trace. The only line that is not grey is main().

    1  __GI_getenv                                                                                                                                                 getenv.c 84 0x7ffff611180d 
    2  qgetenv(const char *)                                                                                                                                                   0x7ffff6ac7121 
    3  QFontEngineFT::QFontEngineFT(QFontDef const&)                                                                                                                           0x7fffee329e78 
    4  ??                                                                                                                                                                      0x7fffee2f327c 
    5  ??                                                                                                                                                                      0x7ffff5ad6eec 
    6  QFontDatabase::findFont(QFontDef const&, int)                                                                                                                           0x7ffff5ad7524 
    7  QFontDatabase::load(QFontPrivate const *, int)                                                                                                                          0x7ffff5ad807d 
    8  QFontPrivate::engineForScript(int) const                                                                                                                                0x7ffff5aaf7f3 
    9  QFontMetricsF::leading() const                                                                                                                                          0x7ffff5acc621 
    10 ??                                                                                                                                                                      0x7ffff5c55af3 
    11 QPainter::drawText(QRect const&, int, QString const&, QRect *)                                                                                                          0x7ffff5c5c774 
    12 QStyle::drawItemText(QPainter *, QRect const&, int, QPalette const&, bool, QString const&, QPalette::ColorRole) const                                                   0x7ffff730e9b7 
    13 QLabel::paintEvent(QPaintEvent *)                                                                                                                                       0x7ffff73ea458 
    14 QWidget::event(QEvent *)                                                                                                                                                0x7ffff72e6bd8 
    15 QFrame::event(QEvent *)                                                                                                                                                 0x7ffff73e3b9e 
    16 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                                 0x7ffff72a3b9c 
    17 QApplication::notify(QObject *, QEvent *)                                                                                                                               0x7ffff72a7f00 
    18 QCoreApplication::notifyInternal2(QObject *, QEvent *)                                                                                                                  0x7ffff6ca6b80 
    19 QWidgetPrivate::sendPaintEvent(QRegion const&)                                                                                                                          0x7ffff72dfefa 
    20 QWidgetPrivate::drawWidget(QPaintDevice *, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)                                                       0x7ffff72e050f 
    21 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *, QList<QObject *> const&, int, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)             0x7ffff72e1274 
    22 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *, QList<QObject *> const&, int, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)             0x7ffff72e10ca 
    23 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *, QList<QObject *> const&, int, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)             0x7ffff72e10ca 
    24 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *, QList<QObject *> const&, int, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)             0x7ffff72e10ca 
    25 QWidgetPrivate::drawWidget(QPaintDevice *, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)                                                       0x7ffff72e00b2 
    26 ??                                                                                                                                                                      0x7ffff72b09aa 
    27 ??                                                                                                                                                                      0x7ffff72b1085 
    28 ??                                                                                                                                                                      0x7ffff7304bc3 
    29 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                                 0x7ffff72a3b9c 
    30 QApplication::notify(QObject *, QEvent *)                                                                                                                               0x7ffff72a7f00 
    31 QCoreApplication::notifyInternal2(QObject *, QEvent *)                                                                                                                  0x7ffff6ca6b80 
    32 QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *)                                                                                0x7ffff59daaa9 
    33 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *)                                                                    0x7ffff59db63d 
    34 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)                                                                                   0x7ffff59bcb23 
    35 ??                                                                                                                                                                      0x7fffee2f1550 
    36 g_main_context_dispatch                                                                                                                                                 0x7ffff45001a7 
    37 ??                                                                                                                                                                      0x7ffff4500400 
    38 g_main_context_iteration                                                                                                                                                0x7ffff45004ac 
    39 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)                                                                                              0x7ffff6cf6177 
    40 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)                                                                                                                 0x7ffff6ca4bca 
    41 QCoreApplication::exec()                                                                                                                                                0x7ffff6caca5d 
    42 main                                                                                                                                                        main.cpp 15 0x400cff       
    


  • @mstoth You most probably have a memory handling problem, like trying to read something through a null pointer. Can you run your program through an analysis tool like Valgrind memory error detector?


  • Moderators

    @mstoth What are the Qt version, compiler and OS?



  • Qt Creator 4.0.3
    Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit)
    Built on Jul 5 2016 01:05:50
    From revision ce4ddcb060
    Running on Ubuntu 16.04

    Running Valgrind produces the following output

    //==3200== Invalid read of size 2
    ==3200==    at 0x67AF80D: getenv (getenv.c:84)
    ==3200==    by 0x5B58120: qgetenv(char const*) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.1)
    ==3200==    by 0xEB50E77: QFontEngineFT::QFontEngineFT(QFontDef const&) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5XcbQpa.so.5.6.1)
    ==3200==    by 0xEB1A27B: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5XcbQpa.so.5.6.1)
    ==3200==    by 0x6D35EEB: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D36523: QFontDatabase::findFont(QFontDef const&, int) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D3707C: QFontDatabase::load(QFontPrivate const*, int) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D0E7F2: QFontPrivate::engineForScript(int) const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D2B620: QFontMetricsF::leading() const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6EB4AF2: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6EBB773: QPainter::drawText(QRect const&, int, QString const&, QRect*) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x54149B6: QStyle::drawItemText(QPainter*, QRect const&, int, QPalette const&, bool, QString const&, QPalette::ColorRole) const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==  Address 0x1 is not stack'd, malloc'd or (recently) free'd
    ==3200== 
    ==3200== 
    ==3200== Process terminating with default action of signal 11 (SIGSEGV)
    ==3200==  Access not within mapped region at address 0x1
    ==3200==    at 0x67AF80D: getenv (getenv.c:84)
    ==3200==    by 0x5B58120: qgetenv(char const*) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.1)
    ==3200==    by 0xEB50E77: QFontEngineFT::QFontEngineFT(QFontDef const&) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5XcbQpa.so.5.6.1)
    ==3200==    by 0xEB1A27B: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5XcbQpa.so.5.6.1)
    ==3200==    by 0x6D35EEB: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D36523: QFontDatabase::findFont(QFontDef const&, int) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D3707C: QFontDatabase::load(QFontPrivate const*, int) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D0E7F2: QFontPrivate::engineForScript(int) const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6D2B620: QFontMetricsF::leading() const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6EB4AF2: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x6EBB773: QPainter::drawText(QRect const&, int, QString const&, QRect*) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Gui.so.5.6.1)
    ==3200==    by 0x54149B6: QStyle::drawItemText(QPainter*, QRect const&, int, QPalette const&, bool, QString const&, QPalette::ColorRole) const (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==  If you believe this happened as a result of a stack
    ==3200==  overflow in your program's main thread (unlikely but
    ==3200==  possible), you can try to increase the size of the
    ==3200==  main thread stack using the --main-stacksize= flag.
    ==3200==  The main thread stack size used in this run was 8388608.
    ==3200== 
    ==3200== HEAP SUMMARY:
    ==3200==     in use at exit: 4,544,622 bytes in 35,589 blocks
    ==3200==   total heap usage: 147,414 allocs, 111,825 frees, 22,561,733 bytes allocated
    ==3200== 
    ==3200== LEAK SUMMARY:
    ==3200==    definitely lost: 2,864 bytes in 11 blocks
    ==3200==    indirectly lost: 13,203 bytes in 557 blocks
    ==3200==      possibly lost: 16,500 bytes in 206 blocks
    ==3200==    still reachable: 4,191,055 bytes in 33,309 blocks
    ==3200==                       of which reachable via heuristic:
    ==3200==                         length64           : 7,880 bytes in 116 blocks
    ==3200==                         newarray           : 2,112 bytes in 52 blocks
    ==3200==                         multipleinheritance: 304 bytes in 2 blocks
    ==3200==         suppressed: 0 bytes in 0 blocks
    ==3200== Rerun with --leak-check=full to see details of leaked memory
    ==3200== 
    ==3200== For counts of detected and suppressed errors, rerun with: -v
    ==3200== Use --track-origins=yes to see where uninitialised values come from
    ==3200== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
    Segmentation fault (core dumped)
    

    And earlier there was several mentions of conditional jumps based on uninitialized values

    //==3200== Memcheck, a memory error detector
    ==3200== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==3200== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
    ==3200== Command: ./GenisysVoicesPanel
    ==3200== 
    ==3200== Conditional jump or move depends on uninitialised value(s)
    ==3200==    at 0x1269D13D: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x7E031D3: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1D9A5: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1E554: g_signal_emit_by_name (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E0A8F7: g_object_set_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E0AFCB: g_object_set (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x548C7A5: ??? (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==    by 0x5415D2C: QStyleFactory::create(QString const&) (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==    by 0x53AB363: QApplication::style() (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==    by 0x53AB5C4: QApplicationPrivate::initialize() (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==    by 0x53AB613: QApplicationPrivate::init() (in /home/bbb_developer/Qt/5.6/gcc_64/lib/libQt5Widgets.so.5.6.1)
    ==3200==    by 0x400CDC: main (main.cpp:12)
    ==3200== 
    ==3200== Conditional jump or move depends on uninitialised value(s)
    ==3200==    at 0x84C93F8: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.1)
    ==3200==    by 0x126A0734: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126A0D38: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126A106E: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x7E02FA4: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E14AFB: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1DD5B: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1E08E: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x1282FB53: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x12830E67: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126CFA32: gtk_fixed_put (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x7E060A6: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200== 
    ==3200== Conditional jump or move depends on uninitialised value(s)
    ==3200==    at 0x84C9425: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.1)
    ==3200==    by 0x126A0734: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126A0D38: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126A106E: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x7E02FA4: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E14AFB: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1DD5B: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x7E1E08E: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200==    by 0x1282FB53: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x12830E67: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x126CFA32: gtk_fixed_put (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30)
    ==3200==    by 0x7E060A6: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
    ==3200== 
    

    However going from this information to the source of the problem is still a mystery to me.
    None of the references seem to indicate particular places in my code.
    Any ideas?



  • @mstoth It looks, based on that valgrind, that you are cleaning up an object with messages still in the queue.

    Do you ever delete a QWidget of yours explicitly? If so try using widget->deleteLater() instead.

    The memory has definitely been deleted, hence the crash. It's almost assuredly in your code somewhere and has nothing to do with getenv from what I can tell.



  • @ambershark The only object I am deleting is the ui object in the destructors. Do you see anything that indicates what object is being deleted? I can't tell how you know based on the valgrind that i am cleaning up an object with messages still in the queue. Can you tell me how you see that?



  • @ambershark It's a guess based on this line right here:

    Address 0x1 is not stack'd, malloc'd or (recently) free'd

    The usual culprit in cases like this is a cleaned up QWidget that was still in use. Sometimes it feels like deleting a widget at a certain point is ok and it won't get used again but a lot of times that widget still has messages in the event queue. When those messages get processed the object is no longer valid and causes these types of issues. This is why

    So valgrind itself isn't telling me that but with the object that was deleted coupled with many years of experience in Qt, I guessed that may be the issue. I would need a lot more information (and code) to be able to find the actual problem, but tried to guide you with the information you posted.

    Another problem you may be experiencing based on the info you provided is an unclean build. Does this project use any so's that you build as part of your build step? Sometimes when you have a bad build you will see weird crashes like this and when you say you have to save after each small step that leads me to think you may have issues with reusing already compiled objects.

    Oh you can also try actually stepping through it with a debugger while it's running and check the object in question yourself. I'm pretty sure you will find it's memory has been deleted/corrupted.



  • Thank you for your help. I'll keep working on this and hopefully get to the root cause.



  • @mstoth Good luck! If you get more information I'd be happy to try and help solve it.

    Also, have you tried it on any other systems? Something besides Ubuntu? Sometimes Ubuntu does funny things compared to other linux distros. Maybe there is an issue with the system fonts that could be causing it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.