为什么我的应用程序在关闭时有时会因SIGSEGV而崩溃? 我用C++编写了一个应用程序,使用Qt4.7.4。启动时,它加载一些自编动态库,这些库也使用Qt(如果这在某种程度上有用的话)

为什么我的应用程序在关闭时有时会因SIGSEGV而崩溃? 我用C++编写了一个应用程序,使用Qt4.7.4。启动时,它加载一些自编动态库,这些库也使用Qt(如果这在某种程度上有用的话),c++,qt,segmentation-fault,C++,Qt,Segmentation Fault,关闭应用程序时,有时它会因SIGSEGV和以下回溯而崩溃: #0 malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5155 #1 0x00007ffff5591659 in malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5115 #2 _int_free (av=0x7ffff58b21c0, p=<optimized out>) at malloc.c:5034 #3

关闭应用程序时,有时它会因SIGSEGV和以下回溯而崩溃:

#0  malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5155
#1  0x00007ffff5591659 in malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5115
#2  _int_free (av=0x7ffff58b21c0, p=<optimized out>) at malloc.c:5034
#3  0x00007ffff5594d7c in __GI___libc_free (mem=<optimized out>) at malloc.c:3738
#4  0x00007ffff5e9e0ac in QString::free (d=0xdb0290) at tools/qstring.cpp:1186
#5  0x00007fffe60b3d83 in ~QString (this=0xba0328, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qstring.h:883
#6  node_destruct (to=0xba0328, from=0xba0328, this=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qlist.h:420
#7  QList<QString>::free (data=0xba0310, this=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qlist.h:744
#8  0x00007fffe60c2b49 in ~QList (this=0xba0388, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qlist.h:719
#9  ~QStringList (this=0xba0388, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qstringlist.h:66
#10 ~SignalHook (this=0xba0358, __in_chrg=<optimized out>) at qdbusconnection_p.h:121
#11 ~QHashNode (this=0xba0340, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qhash.h:216
#12 QHash<QString, QDBusConnectionPrivate::SignalHook>::deleteNode2 (node=0xba0340) at ../../include/QtCore/../../src/corelib/tools/qhash.h:519
#13 0x00007ffff5e754da in QHashData::free_helper (this=0xd8aec0, node_delete=0x7fffe60c2ae0 <QHash<QString, QDBusConnectionPrivate::SignalHook>::deleteNode2(QHashData::Node*)>) at tools/qhash.cpp:271
#14 0x00007fffe60ba733 in freeData (x=<optimized out>, this=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qhash.h:568
#15 ~QHash (this=<optimized out>, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qhash.h:284
#16 ~QMultiHash (this=0xba3498, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qhash.h:922
#17 ~QMultiHash (this=0xba3498, __in_chrg=<optimized out>) at qdbusintegrator.cpp:998
#18 QDBusConnectionPrivate::~QDBusConnectionPrivate (this=0xba33f0, __in_chrg=<optimized out>) at qdbusintegrator.cpp:998
#19 0x00007fffe60ba939 in QDBusConnectionPrivate::~QDBusConnectionPrivate (this=0xba33f0, __in_chrg=<optimized out>) at qdbusintegrator.cpp:1016
#20 0x00007fffe60afe43 in ~QDBusDefaultConnection (this=0xba55a0, __in_chrg=<optimized out>) at qdbusconnection.cpp:993
#21 QGlobalStaticDeleter<QDBusDefaultConnection>::~QGlobalStaticDeleter (this=0x7fffe63102f8, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/global/qglobal.h:1825
#22 0x00007ffff5553821 in __run_exit_handlers (status=0, listp=0x7ffff58b05a8, run_list_atexit=true) at exit.c:78
#23 0x00007ffff55538a5 in __GI_exit (status=<optimized out>) at exit.c:100
#24 0x00007ffff5539314 in __libc_start_main (main=0x493935 <main(int, char**)>, argc=1, ubp_av=0x7fffffffde58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde48) at libc-start.c:258
#25 0x0000000000421a99 in _start ()
#0 malloc_合并(av=0x7ffff58b21c0)在malloc.c:5155
#1 0x00007FF5591659在malloc_合并(av=0x7ffff58b21c0)在malloc.c:5115
#在malloc.c:5034处有2个无内部(av=0x7ffff58b21c0,p=)
#3 0x00007FF5594D7C在malloc.c:3738
#在tools/QString.cpp:1186处的QString::free(d=0xdb0290)中的4 0x00007ffff5e9e0ac
#5 0x00007fffe60b3d83 in~QString(此=0xba0328,uu in_chrg=)位于../../include/QtCore/../src/corelib/tools/QString.h:883
#位于.././include/QtCore/./../src/corelib/tools/qlist.h:420的6节点_自毁(to=0xba0328,from=0xba0328,this=)
#7 QList::free(data=0xba0310,this=)位于../../include/QtCore/../src/corelib/tools/QList.h:744
#8 0x00007fffe60c2b49 in~QList(this=0xba0388,uu in_chrg=)位于../../include/QtCore/../src/corelib/tools/QList.h:719
#9~QStringList(this=0xba0388,u in_chrg=)位于../../include/QtCore/../src/corelib/tools/QStringList.h:66
#QDBUS连接处的10~信号钩(此=0xba0358,uuu in_uchrg=)p.h:121
#11~QHashNode(this=0xba0340,u in_chrg=)位于../../include/QtCore/../src/corelib/tools/qhash.h:216
#12 QHash::deleteNode2(node=0xba0340)位于.././include/QtCore/../../src/corelib/tools/QHash.h:519
#在tools/qhash.cpp:271处,QHashData::free_helper(this=0xd8aec0,node_delete=0x7fffe60c2ae0)中的13 0x00007ffff5e754da
#14 0x00007fffe60ba733在../../include/QtCore/../src/corelib/tools/qhash.h处的自由数据(x=,this=)中
#15~QHash(this=,u in_chrg=)位于../../include/QtCore/../src/corelib/tools/QHash.h:284
#16~QMultiHash(this=0xba3498,u in_chrg=)位于../../include/QtCore/../src/corelib/tools/qhash.h:922
#17~qdbusintegrator.cpp:998处的QMultiHash(this=0xba3498,u in_chrg=)
#18 QDBusConnectionPrivate::~QDBusConnectionPrivate(this=0xba33f0,u in_chrg=)位于qdbusintegrator.cpp:998
#QDBusConnectionPrivate:中的19 0x00007fffe60ba939:~QDBusConnectionPrivate(this=0xba33f0,uuu in_chrg=)位于qdbusintegrator.cpp:1016
#qdbusconnection处的20 0x00007fffe60afe43 in~QDBusDefaultConnection(this=0xba55a0,uuuu in_chrg=)cpp:993
#21 QGlobalStaticDeleter::~QGlobalStaticDeleter(this=0x7fffe63102f8,u in_chrg=)位于../../include/QtCore/../src/corelib/global/qglobal.h:1825
#22 0x00007FF5553821在退出时运行退出处理程序(状态=0,列表=0x7ffff58b05a8,运行列表atexit=true)。c:78
#23 0x00007FF55538A5位于出口处的GI出口(状态=)中。c:100
#24 0x00007FF5539314在libc start处的uuu libc_start_main(main=0x493935,argc=1,ubp_av=0x7fffffffde58,init=,fini=,rtld_fini=,stack_end=0x7fffffde48)中。c:258
#25 0x0000000000421a99英寸(U开始)
有时候这个

#0  malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5155
#1  0x00007ffff5591659 in malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5115
#2  _int_free (av=0x7ffff58b21c0, p=<optimized out>) at malloc.c:5034
#3  0x00007ffff5594d7c in __GI___libc_free (mem=<optimized out>) at malloc.c:3738
#4  0x00007ffff5f4d5a9 in ~QVector (this=0x767c40, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qvector.h:119
#5  QGlobalStaticDeleter<QVector<QCustomTypeInfo> >::~QGlobalStaticDeleter (this=0x7ffff6274898, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/global/qglobal.h:1825
#6  0x00007ffff5553c3d in __cxa_finalize (d=0x7ffff6273d20) at cxa_finalize.c:56
#7  0x00007ffff5e3e0a6 in __do_global_dtors_aux () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#8  0x00007fffffffd7c0 in ?? ()
#9  0x00007fffffffdd30 in ?? ()
#10 0x00007ffff5f9e5a1 in _fini () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#11 0x000000000000009f in ?? ()
#12 0x00007ffff7deb105 in ?? () from /lib64/ld-linux-x86-64.so.2
#0 malloc_合并(av=0x7ffff58b21c0)在malloc.c:5155
#1 0x00007FF5591659在malloc_合并(av=0x7ffff58b21c0)在malloc.c:5115
#在malloc.c:5034处有2个无内部(av=0x7ffff58b21c0,p=)
#3 0x00007FF5594D7C在malloc.c:3738
#4 0x00007FF5F4D5A9 in~QVector(该值=0x767c40,uu in_chrg=)位于../../include/QtCore/../../src/corelib/tools/QVector.h:119
#5 QGlobalStaticDeleter::~QGlobalStaticDeleter(this=0x7ffff6274898,u in_chrg=)位于../../include/QtCore/../src/corelib/global/qglobal.h:1825
#6 0x00007FF5553C3D位于cxa\U finalize处的cxa\U finalize(d=0x7ffff6273d20)中。c:56
#7 0x00007FF5E3E0A6,位于/usr/lib/x86\u 64-linux-gnu/libQtCore.so.4中的
#8 0x00007FFFFFF7C0英寸??()
#9 0x00007fffffffdd30英寸??()
#10 0x00007ffff5f9e5a1位于/usr/lib/x86_64-linux-gnu/libQtCore.so.4的fini()中
#11 0x000000000000009f英寸??()
#12 0x00007FF7DEB105英寸??()来自/lib64/ld-linux-x86-64.so.2
还是这个

#0  malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5155
#1  0x00007ffff5591659 in malloc_consolidate (av=0x7ffff58b21c0) at malloc.c:5115
#2  _int_free (av=0x7ffff58b21c0, p=<optimized out>) at malloc.c:5034
#3  0x00007ffff5594d7c in __GI___libc_free (mem=<optimized out>) at malloc.c:3738
#4  0x00007ffff5e86bbe in freeData (x=<optimized out>, this=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qmap.h:654
#5  ~QMap (this=0x10af198, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qmap.h:187
#6  ~QMap (this=0x10af198, __in_chrg=<optimized out>) at tools/qvector.h:430
#7  ~QRegExpAutomatonState (this=0x10af180, __in_chrg=<optimized out>) at tools/qregexp.cpp:947
#8  QVector<QRegExpAutomatonState>::free (x=0x10af0f0, this=<optimized out>) at tools/qvector.h:438
#9  0x00007ffff5e969a9 in clear (this=<optimized out>) at tools/qcache.h:139
#10 ~QCache (this=<optimized out>, __in_chrg=<optimized out>) at tools/qcache.h:103
#11 QGlobalStaticDeleter<QCache<QRegExpEngineKey, QRegExpEngine> >::~QGlobalStaticDeleter (this=0x7ffff6274368, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/global/qglobal.h:1825
#12 0x00007ffff5553821 in __run_exit_handlers (status=0, listp=0x7ffff58b05a8, run_list_atexit=true) at exit.c:78
#13 0x00007ffff55538a5 in __GI_exit (status=<optimized out>) at exit.c:100
#14 0x00007ffff5539314 in __libc_start_main (main=0x493935 <main(int, char**)>, argc=1, ubp_av=0x7fffffffde58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde48) at libc-start.c:258
#15 0x0000000000421a99 in _start ()
#0 malloc_合并(av=0x7ffff58b21c0)在malloc.c:5155
#1 0x00007FF5591659在malloc_合并(av=0x7ffff58b21c0)在malloc.c:5115
#在malloc.c:5034处有2个无内部(av=0x7ffff58b21c0,p=)
#3 0x00007FF5594D7C在malloc.c:3738
#4 0x00007ffff5e86bbe在../../include/QtCore/../src/corelib/tools/qmap.h处的自由数据(x=,this=)中
#5~QMap(this=0x10af198,u in_chrg=)位于../../include/QtCore/../src/corelib/tools/QMap.h:187
#6~QMap(this=0x10af198,uu in_chrg=)位于tools/qvector.h:430
#7~qregexpautomationstate(this=0x10af180,u in_chrg=)位于tools/qregexp.cpp:947
#8 QVector::free(x=0x10af0f0,this=)位于tools/QVector.h:438
#9 0x00007FF5E969A9在tools/qcache.h:139处处于清除状态(此=)
#10~QCache(this=,u in_chrg=)位于tools/QCache.h:103
#11 QGlobalStaticDeleter::~QGlobalStaticDeleter(this=0x7ffff6274368,u in_chrg=)位于../../include/QtCore/../src/corelib/global/qglobal.h:1825
#12 0x00007FF5553821位于退出时的“运行”退出”处理程序中(状态=0,列表=0x7ffff58b05a8,运行列表atexit=true)。c:78
#13 0x00007FF55538A5位于出口处的GI出口(状态=)中。c:100
#14 0x00007FF5539314在libc start的uuu libc_start_main(main=0x493935,argc=1,ubp_av=0x7fffffffde58,init=,fini=,rtld_fini=,stack_end=0x7fffffde48)中。c:258
#15 0x0000000000421a99英寸(U开始)
还有一些

我认为它们都是相关的,但我真的不知道如何以及为什么会发生这种情况(请注意,在跟踪中没有列出我的任何代码)


非常感谢您提供了一些提示,说明了为什么会发生这种情况,或者我应该从哪里开始搜索。

从coredumps的堆栈帧中,您似乎在某个地方损坏了堆,或者正在释放无效指针


调试此类问题的最佳方法是使用valgrind或Rational Purify plus等内存评测工具评测代码(谷歌搜索应该有很多这样的工具)。这些分析工具将指出问题的根本原因。

我找到了问题的解决方案:我将一个静态库链接到我的主应用程序