sigsegv 問題的調是

_
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. 

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have written an application in c++ which uses Qt 4.7.4. When starting up, it loads some selfwritten dynamic libraries which also use Qt (if this could be useful in a way).

When closing the application, sometimes it crashes with a SIGSEGV and the following backtrace:

#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 ()

and sometimes this one

#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

or this one

#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 ()

And there are some more...

I think they are all related but I really can't figure out how and why this occurs (note that in no trace any of my code is listed).

Thank you very much for some hints, why this could occur or where I should start searching.

share improve this question
 

2 Answers

up vote 5 down vote accepted

I found the solution to my problem: I linked a static library to my main application and my dynamic libraries. This static library was using Qt which uses global variables. At application shutdown the dynamic libraries were unloaded from my application. This resulted in deleting the global variables of Qt. But the shutdown of the application itselves resulted in deleting the same global variables once more which ended in the SIGSEGVs.

The solution was to change the static library to a dynamic one. Now the global variables only get deleted once, since all the shared libraries and the main application are using the "same" Qt code.

share improve this answer
 

From the stack frames of coredumps it seems that you have corrupted the heap somewhere or are freeing invalid pointers.

The best way to debug such problems is to profile your code with memory profiling tools like valgrind or Rational Purify plus(there are many such tools a google search should help). These profiling tools shall point out the root cause of the problem.

share improve this answer
 

Your Answer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值