I am experiencing some stange problem in python extension in c++. I appreciate any help or suggestions.
To set context.
I am using embedded python in C++ to execute python scripts. I am also using python extension in c++ to give ability to python script to call the C++ function.
What is problem?
When I comment method entry from modules “method table” like I have shown below. Application never crashes or I am not experiencing segfault at all.
static PyMethodDef sa_methods[] = {
//{"GetBlue",(PyCFunction)sa_GetBlue,METH_VARARGS,PyDoc_STR("fetches Blue color")},
//{"GetRed",(PyCFunction)sa_GetRed,METH_VARARGS,PyDoc_STR("fetches Red color")},
{"GetYellow",(PyCFunction)sa_GetYellow,METH_VARARGS,PyDoc_STR("fetches yellow color")},
{"GetPink",(PyCFunction)sa_GetPink,METH_VARARGS,PyDoc_STR("fetches pink color")},
{NULL, NULL, 0, NULL}
};
When I remove method comments from the method entry from modules “method table” like I have shown below. Application always crashes in between processing 20000 to 50000 requests randomly.
static PyMethodDef sa_methods[] = {
{"GetBlue",(PyCFunction)sa_GetBlue,METH_VARARGS,PyDoc_STR("fetches Blue color")},
{"GetRed",(PyCFunction)sa_GetRed,METH_VARARGS,PyDoc_STR("fetches Red color")},
{"GetYellow",(PyCFunction)sa_GetYellow,METH_VARARGS,PyDoc_STR("fetches yellow color")},
{"GetPink",(PyCFunction)sa_GetPink,METH_VARARGS,PyDoc_STR("fetches pink color")},
{NULL, NULL, 0, NULL}
};
I have kept above two methods empty and they are merely returning Py_False.
Please find below the stack trace that I am getting every time.
#0 0x00002b700146c4d7 in PyNumber_CoerceEx (pv=0x41801798, pw=0x41801790) at Objects/object.c:1599
#1 0x00002b700142d6e3 in binary_op1 (v=0x2aaaac079600, w=0x2b7001750550, op_slot=16) at Objects/abstract.c:929
#2 0x00002b7001431e08 in PyNumber_Multiply (v=0x41801798, w=0x41801790) at Objects/abstract.c:1188
#3 0x00002b70014c4326 in PyEval_EvalFrameEx (f=0x8127780, throwflag=<value optimized out>) at Python/ceval.c:1118
#4 0x00002b70014c8493 in call_function (f=0x996e660, throwflag=<value optimized out>) at Python/ceval.c:3792
#5 PyEval_EvalFrameEx (f=0x996e660, throwflag=<value optimized out>) at Python/ceval.c:2389
#6 0x00002b70014c8493 in call_function (f=0x2aaac30aeb50, throwflag=<value optimized out>) at Python/ceval.c:3792
#7 PyEval_EvalFrameEx (f=0x2aaac30aeb50, throwflag=<value optimized out>) at Python/ceval.c:2389
#8 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaaad7dc558, globals=<value optimized out>, locals=<value optimized out>, args=0x2aaac6ab59a0, argcount=2,
kws=0x2aaac6ab59b0, kwcount=0, defs=0x7819128, defcount=1, closure=0x0) at Python/ceval.c:2968
#9 0x00002b70014c6df3 in call_function (f=0x2aaac6ab57d0, throwflag=<value optimized out>) at Python/ceval.c:3802
#10 PyEval_EvalFrameEx (f=0x2aaac6ab57d0, throwflag=<value optimized out>) at Python/ceval.c:2389
#11 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaabdf8e828, globals=<value optimized out>, locals=<value optimized out>, args=0x2aaac65bcbf0, argcount=2,
kws=0x2aaac65bcc00, kwcount=0, defs=0x7819c28, defcount=1, closure=0x0) at Python/ceval.c:2968
#12 0x00002b70014c6df3 in call_function (f=0x2aaac65bca40, throwflag=<value optimized out>) at Python/ceval.c:3802
#13 PyEval_EvalFrameEx (f=0x2aaac65bca40, throwflag=<value optimized out>) at Python/ceval.c:2389
#14 0x00002b70014c8493 in call_function (f=0x2aaac6301630, throwflag=<value optimized out>) at Python/ceval.c:3792
#15 PyEval_EvalFrameEx (f=0x2aaac6301630, throwflag=<value optimized out>) at Python/ceval.c:2389
#16 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x6c7f558, globals=<value optimized out>, locals=<value optimized out>, args=0x2aaac55963e8, argcount=2,
kws=0x2aaac55963f8, kwcount=0, defs=0xd83fce8, defcount=1, closure=0x0) at Python/ceval.c:2968
#17 0x00002b70014c6df3 in call_function (f=0x2aaac5596240, throwflag=<value optimized out>) at Python/ceval.c:3802
#18 PyEval_EvalFrameEx (f=0x2aaac5596240, throwflag=<value optimized out>) at Python/ceval.c:2389
#19 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x6c7fcd8, globals=<value optimized out>, locals=<value optimized out>, args=0x2aaac6fbc328, argcount=2,
kws=0x2aaac6fbc338, kwcount=0, defs=0xd83fc68, defcount=1, closure=0x0) at Python/ceval.c:2968
#20 0x00002b70014c6df3 in call_function (f=0x2aaac6fbc1a0, throwflag=<value optimized out>) at Python/ceval.c:3802
#21 PyEval_EvalFrameEx (f=0x2aaac6fbc1a0, throwflag=<value optimized out>) at Python/ceval.c:2389
#22 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x6c7f648, globals=<value optimized out>, locals=<value optimized out>, args=0x1, argcount=0, kws=0x2aaac3e32558,
kwcount=0, defs=0xd83ffa8, defcount=1, closure=0x0) at Python/ceval.c:2968
#23 0x00002b70014c6df3 in call_function (f=0x2aaac3e323d0, throwflag=<value optimized out>) at Python/ceval.c:3802
#24 PyEval_EvalFrameEx (f=0x2aaac3e323d0, throwflag=<value optimized out>) at Python/ceval.c:2389
#25 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaaad7f70a8, globals=<value optimized out>, locals=<value optimized out>, args=0x0, argcount=0, kws=0x1325c6a8,
kwcount=0, defs=0x0, defcount=0, closure=0x2aaaad18e990) at Python/ceval.c:2968
#26 0x00002b70014c6df3 in call_function (f=0x1325c480, throwflag=<value optimized out>) at Python/ceval.c:3802
#27 PyEval_EvalFrameEx (f=0x1325c480, throwflag=<value optimized out>) at Python/ceval.c:2389
#28 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaaad7f77b0, globals=<value optimized out>, locals=<value optimized out>, args=0x1, argcount=1, kws=0x2aaac5ec1d08,
kwcount=0, defs=0x2aaaacfdf5e8, defcount=1, closure=0x0) at Python/ceval.c:2968
#29 0x00002b70014c6df3 in call_function (f=0x2aaac5ec1b00, throwflag=<value optimized out>) at Python/ceval.c:3802
#30 PyEval_EvalFrameEx (f=0x2aaac5ec1b00, throwflag=<value optimized out>) at Python/ceval.c:2389
#31 0x00002b70014c8493 in call_function (f=0xa926080, throwflag=<value optimized out>) at Python/ceval.c:3792
#32 PyEval_EvalFrameEx (f=0xa926080, throwflag=<value optimized out>) at Python/ceval.c:2389
#33 0x00002b70014c8493 in call_function (f=0x8e4bd40, throwflag=<value optimized out>) at Python/ceval.c:3792
#34 PyEval_EvalFrameEx (f=0x8e4bd40, throwflag=<value optimized out>) at Python/ceval.c:2389
#35 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaabc9f7648, globals=<value optimized out>, locals=<value optimized out>, args=0x9ff5f58, argcount=1,
---Type <return> to continue, or q <return> to quit---
kws=0x9ff5f60, kwcount=0, defs=0x0, defcount=0, closure=0x2aaaacfdfc50) at Python/ceval.c:2968
#36 0x00002b70014c6df3 in call_function (f=0x9ff5dc0, throwflag=<value optimized out>) at Python/ceval.c:3802
#37 PyEval_EvalFrameEx (f=0x9ff5dc0, throwflag=<value optimized out>) at Python/ceval.c:2389
#38 0x00002b70014c8493 in call_function (f=0xdb993e0, throwflag=<value optimized out>) at Python/ceval.c:3792
#39 PyEval_EvalFrameEx (f=0xdb993e0, throwflag=<value optimized out>) at Python/ceval.c:2389
#40 0x00002b70014c8d9f in PyEval_EvalCodeEx (co=0x2aaabd820990, globals=<value optimized out>, locals=<value optimized out>, args=0x2aaaacfdf8a8, argcount=1, kws=0x0,
kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2968
#41 0x00002b700145815d in function_call (func=0x7d898c0, arg=0x2aaaacfdf890, kw=0x0) at Objects/funcobject.c:524
#42 0x00002b700142d318 in PyObject_Call (func=0x7d898c0, arg=0x2aaaacfdf890, kw=0x0) at Objects/abstract.c:2492
#43 0x00002b700143cd7f in instancemethod_call (func=<value optimized out>, arg=0x2aaaacfdf890, kw=0x0) at Objects/classobject.c:2579
#44 0x00002b700142d318 in PyObject_Call (func=0x7554690, arg=0x2aaaac04d050, kw=0x0) at Objects/abstract.c:2492
#45 0x00002b70014c0e16 in PyEval_CallObjectWithKeywords (func=0x7554690, arg=0x2aaaac04d050, kw=0x0) at Python/ceval.c:3575
#46 0x00002b70014f9dcd in t_bootstrap (boot_raw=0x2aaac76e67c0) at ./Modules/threadmodule.c:425
#47 0x00000033c720677d in start_thread () from /lib64/libpthread.so.0
#48 0x00000033c66d33ed in clone () from /lib64/libc.so.6
I got solution for this problem which has ultimately gave me as well as my client huge relief.
And here is the reason and solution.
The functions “sa_GetBlue” and "sa_GetRed" was returning “Py_False”. Before returning “Py_False” or “Py_True” you need to increase the reference count of the variable holding these values otherwise It may corrupt memory state of the interpreter; it would not crash immediately but may crash at any point of time. In my case, It was crashing after processing 20000 to 50000 requests.
Please check below link to get more idea about what I am trying to explain.
why-does-python-keep-a-reference-count-on-false-and-true
#doomster and #Omnifarious; Thank you for your comment and direction that you have provided.
Related
I was doing a set of 10 concurrent tests when ClickHouse became deadlocked.
The following SQL
select
id,
sum(a) as a,
sum(b) as b,
sum(c) as c,
round(sum(d), 2) as d
from f_table
where xxx
And I ran pstack my-clickhouse-server-process-id and got some __lll_lock_wait.
Sorry for posting so many thread stack logs, I thought more information may give you some ideas.
Since this reproduce is not stable at present, I haven't posted it on GitHub's issue.
I read https://github.com/ClickHouse/ClickHouse/issues/4316 but I'm not really sure what the fix has achieved. My current version is 19.14.7.15.
Here are a few typical stacks:
Thread 1278 (Thread 0x7f89a23c6700 (LWP 18345)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#6 0x000055dc6806c91e in ?? ()
#7 <signal handler called>
#8 0x000055dc6b87d21d in ?? ()
#9 0x000055dc6b87da1e in LZ4::decompress(char const*, char*, unsigned long, unsigned long, LZ4::PerformanceStatistics&) ()
#10 0x000055dc6b184eb6 in DB::ICompressionCodec::decompress(char const*, unsigned int, char*) const ()
#11 0x000055dc6b17dd37 in DB::CompressedReadBufferBase::decompress(char*, unsigned long, unsigned long) ()
#12 0x000055dc6b8544b5 in DB::CompressedReadBufferFromFile::nextImpl() ()
#13 0x000055dc6b854609 in DB::CompressedReadBufferFromFile::seek(unsigned long, unsigned long) ()
#14 0x000055dc6b6519c8 in DB::MergeTreeReaderStream::seekToMark(unsigned long) ()
#15 0x000055dc6bb1d637 in ?? ()
#16 0x000055dc681ecc78 in DB::IDataType::deserializeBinaryBulkWithMultipleStreams(DB::IColumn&, unsigned long, DB::IDataType::DeserializeBinaryBulkSettings&, std::shared_ptr<DB::IDataType::DeserializeBinaryBulkState>&) const ()
#17 0x000055dc6bb1f64c in DB::MergeTreeReader::readData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DB::IDataType const&, DB::IColumn&, unsigned long, bool, unsigned long, bool) ()
#18 0x000055dc6bb1fdfb in DB::MergeTreeReader::readRows(unsigned long, bool, unsigned long, DB::Block&) ()
#19 0x000055dc6bb197be in DB::MergeTreeRangeReader::DelayedStream::finalize(DB::Block&) ()
#20 0x000055dc6bb1b988 in DB::MergeTreeRangeReader::continueReadingChain(DB::MergeTreeRangeReader::ReadResult&) ()
#21 0x000055dc6bb1c1ae in DB::MergeTreeRangeReader::read(unsigned long, std::vector<DB::MarkRange, std::allocator<DB::MarkRange> >&) ()
#22 0x000055dc6baec6d3 in DB::MergeTreeBaseSelectBlockInputStream::readFromPartImpl() ()
#23 0x000055dc6baed1a5 in DB::MergeTreeBaseSelectBlockInputStream::readImpl() ()
#24 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#25 0x000055dc6b8bf6c6 in DB::FilterBlockInputStream::readImpl() ()
#26 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#27 0x000055dc6b8b81ef in DB::ExpressionBlockInputStream::readImpl() ()
#28 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#29 0x000055dc6b8f1b9a in DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::thread(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long) ()
#30 0x000055dc6b8f265d in _ZZN20ThreadFromGlobalPoolC4IMN2DB23ParallelInputsProcessorINS1_35ParallelAggregatingBlockInputStream7HandlerEEEFvSt10shared_ptrINS1_17ThreadGroupStatusEEmEJPS5_S8_RmEEEOT_DpOT0_ENKUlvE_clEv ()
#31 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#32 0x000055dc6dd01b60 in ?? ()
#33 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#34 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
and
Thread 1231 (Thread 0x7f897ebff700 (LWP 18392)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#6 0x000055dc6806c91e in ?? ()
#7 <signal handler called>
#8 0x00007f89a8b91963 in pthread_cond_wait##GLIBC_2.3.2 () from /lib64/libpthread.so.0
#9 0x000055dc6dc8dc0c in std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
#10 0x000055dc6d527cab in Poco::Event::wait() ()
#11 0x000055dc6b8ef2fa in DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::wait() ()
#12 0x000055dc6b8eaff8 in DB::ParallelAggregatingBlockInputStream::execute() ()
#13 0x000055dc6b8ee7e0 in DB::ParallelAggregatingBlockInputStream::readImpl() ()
#14 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#15 0x000055dc6b18a15b in DB::AsynchronousBlockInputStream::calculate() ()
#16 0x000055dc6b18a520 in ?? ()
#17 0x000055dc680958de in ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::_List_iterator<ThreadFromGlobalPool>) ()
#18 0x000055dc68095eee in _ZZN20ThreadFromGlobalPoolC4IZN14ThreadPoolImplIS_E12scheduleImplIvEET_St8functionIFvvEEiSt8optionalImEEUlvE1_JEEEOS4_DpOT0_ENKUlvE_clEv ()
#19 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#20 0x000055dc6dd01b60 in ?? ()
#21 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#22 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
and
Thread 1203 (Thread 0x7f8969ff9700 (LWP 18420)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#6 0x000055dc6806c91e in ?? ()
#7 <signal handler called>
#8 0x00007f89a8b944eb in __lll_lock_wait () from /lib64/libpthread.so.0
#9 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#10 0x000055dc6dd3c87f in ?? ()
#11 0x000055dc6dd35393 in unw_step ()
#12 0x000055dc6dd354b0 in unw_backtrace ()
#13 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#14 0x000055dc6806c91e in ?? ()
#15 <signal handler called>
#16 0x000055dc68bb02ee in DB::NumComparisonImpl<long, unsigned int, DB::EqualsOp<long, unsigned int> >::vector_constant(DB::PODArray<long, 4096ul, Allocator<false, false>, 15ul, 16ul> const&, unsigned int, DB::PODArray<unsigned char, 4096ul, Allocator<false, false>, 15ul, 16ul>&) ()
#17 0x000055dc68be2aac in bool DB::FunctionComparison<DB::EqualsOp, DB::NameEquals>::executeNumLeftType<long>(DB::Block&, unsigned long, DB::IColumn const*, DB::IColumn const*) ()
#18 0x000055dc68cb9496 in DB::FunctionComparison<DB::EqualsOp, DB::NameEquals>::executeImpl(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long) ()
#19 0x000055dc6b8329e4 in DB::PreparedFunctionImpl::execute(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) ()
#20 0x000055dc6ba20231 in DB::ExpressionAction::execute(DB::Block&, bool) const ()
#21 0x000055dc6ba21945 in DB::ExpressionActions::execute(DB::Block&, bool) const ()
#22 0x000055dc6b8bfa08 in DB::FilterBlockInputStream::readImpl() ()
#23 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#24 0x000055dc6b8b81ef in DB::ExpressionBlockInputStream::readImpl() ()
#25 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#26 0x000055dc6b8f1b9a in DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::thread(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long) ()
#27 0x000055dc6b8f265d in _ZZN20ThreadFromGlobalPoolC4IMN2DB23ParallelInputsProcessorINS1_35ParallelAggregatingBlockInputStream7HandlerEEEFvSt10shared_ptrINS1_17ThreadGroupStatusEEmEJPS5_S8_RmEEEOT_DpOT0_ENKUlvE_clEv ()
#28 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#29 0x000055dc6dd01b60 in ?? ()
#30 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#31 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
and
Thread 1202 (Thread 0x7f89697f8700 (LWP 18421)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc680581e0 in StackTrace::StackTrace() ()
#6 0x000055dc6b287535 in DB::Context::getTable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const ()
#7 0x000055dc6b2d32dc in DB::InterpreterInsertQuery::getTable(DB::ASTInsertQuery const&) ()
#8 0x000055dc6b2d3ce7 in DB::InterpreterInsertQuery::execute() ()
#9 0x000055dc680b807a in DB::SystemLog<DB::QueryLogElement>::flushImpl(DB::SystemLog<DB::QueryLogElement>::EntryType) ()
#10 0x000055dc680b87f2 in DB::SystemLog<DB::QueryLogElement>::threadFunction() ()
#11 0x000055dc680b938a in _ZZN20ThreadFromGlobalPoolC4IZN2DB9SystemLogINS1_15QueryLogElementEEC4ERNS1_7ContextERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESE_SE_mEUlvE_JEEEOT_DpOT0_ENKUlvE_clEv ()
#12 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#13 0x000055dc6dd01b60 in ?? ()
#14 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#15 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
and
Thread 1175 (Thread 0x7f888a1f3700 (LWP 18449)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#6 0x000055dc6806c91e in ?? ()
#7 <signal handler called>
#8 0x00007f89a84ab603 in epoll_wait () from /lib64/libc.so.6
#9 0x000055dc6bea48b6 in Poco::Net::SocketImpl::poll(Poco::Timespan const&, int) ()
#10 0x000055dc6bea1d5b in Poco::Net::SocketImpl::receiveBytes(void*, int, int) ()
#11 0x000055dc6be5afaa in DB::ReadBufferFromPocoSocket::nextImpl() ()
#12 0x000055dc6b6e676f in DB::Connection::receivePacket() ()
#13 0x000055dc6b6f69ae in DB::MultiplexedConnections::receivePacket() ()
#14 0x000055dc6b1a8396 in DB::RemoteBlockInputStream::readImpl() ()
#15 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#16 0x000055dc6b3036ac in DB::ParallelInputsProcessor<DB::UnionBlockInputStream::Handler>::loop(unsigned long) ()
#17 0x000055dc6b303d95 in DB::ParallelInputsProcessor<DB::UnionBlockInputStream::Handler>::thread(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long) ()
#18 0x000055dc6b30470d in _ZZN20ThreadFromGlobalPoolC4IMN2DB23ParallelInputsProcessorINS1_21UnionBlockInputStream7HandlerEEEFvSt10shared_ptrINS1_17ThreadGroupStatusEEmEJPS5_S8_RmEEEOT_DpOT0_ENKUlvE_clEv ()
#19 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#20 0x000055dc6dd01b60 in ?? ()
#21 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#22 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
and
Thread 1171 (Thread 0x7f88881ef700 (LWP 18453)):
#0 0x00007f89a8b944ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f89a8b910e2 in pthread_rwlock_rdlock () from /lib64/libpthread.so.0
#2 0x000055dc6dd3c87f in ?? ()
#3 0x000055dc6dd35393 in unw_step ()
#4 0x000055dc6dd354b0 in unw_backtrace ()
#5 0x000055dc68058221 in StackTrace::StackTrace(ucontext_t const&) ()
#6 0x000055dc6806c91e in ?? ()
#7 <signal handler called>
#8 0x00007f89a8b91963 in pthread_cond_wait##GLIBC_2.3.2 () from /lib64/libpthread.so.0
#9 0x000055dc6dc8dc0c in std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
#10 0x000055dc6d580c63 in Poco::Semaphore::wait() ()
#11 0x000055dc6b304da6 in DB::UnionBlockInputStream::readImpl() ()
#12 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#13 0x000055dc6b940442 in DB::Aggregator::mergeStream(std::shared_ptr<DB::IBlockInputStream> const&, DB::AggregatedDataVariants&, unsigned long) ()
#14 0x000055dc6b8d7a5a in DB::MergingAggregatedBlockInputStream::readImpl() ()
#15 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#16 0x000055dc6b8b81ef in DB::ExpressionBlockInputStream::readImpl() ()
#17 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#18 0x000055dc6b8b81ef in DB::ExpressionBlockInputStream::readImpl() ()
#19 0x000055dc6b191637 in DB::IBlockInputStream::read() ()
#20 0x000055dc6b18a15b in DB::AsynchronousBlockInputStream::calculate() ()
#21 0x000055dc6b18a520 in ?? ()
#22 0x000055dc680958de in ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::_List_iterator<ThreadFromGlobalPool>) ()
#23 0x000055dc68095eee in _ZZN20ThreadFromGlobalPoolC4IZN14ThreadPoolImplIS_E12scheduleImplIvEET_St8functionIFvvEEiSt8optionalImEEUlvE1_JEEEOS4_DpOT0_ENKUlvE_clEv ()
#24 0x000055dc6809338c in ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>) ()
#25 0x000055dc6dd01b60 in ?? ()
#26 0x00007f89a8b8ddd5 in start_thread () from /lib64/libpthread.so.0
#27 0x00007f89a84ab02d in clone () from /lib64/libc.so.6
Do you know what caused the deadlock? Why is clickhouse locked while reading?
The concurrency may not seem high.
Most probably you hit that bug https://github.com/ClickHouse/ClickHouse/issues/7383
It was fixed in 19.14.10 or newer.
sim_wrapper.h
#pragma once
#include <pybind11/embed.h>
namespace n_sim
{
namespace py = pybind11;
// __attribute__ needed for pybind to work
class __attribute__((visibility("default"))) Sim
{
public:
Sim();
// python sim class instance we're using
py::object sim;
private:
// python module want to load into our C++ code.
py::module SimWrapModule;
// Needed to initialize pybind. As soon as this goes out of scope, pybind is un-initialized.
py::scoped_interpreter guard{};
};
}
sim_wrapper.cpp
#include <iostream>
#include "sim_wrapper.h"
using namespace n_sim;
Sim::Sim()
{
// import python module
SimWrapModule = py::module::import("wrapper");
// catch return values from python functions
sim = SimWrapModule.attr("initialize_sim")();
}
int main()
{
Sim* SimWrap = new Sim();
py::str name = SimWrap->sim.attr("name");
std::cout << name.cast<std::string>() << std::endl;
return 0;
}
When this program is run it print the name and program closes but it leaves three uncleaned processes. Tried gstack with these processes and all have output like,
$ gstack 22763
#0 0x00000036f42df3c8 in poll () from /lib64/libc.so.6
#1 0x00007f012a43867b in poll_poll () from /opt/debesys/ext/linux/x86-64/release/lib/python2.7/lib-dynload/select.so
#2 0x00007f01346b50cb in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#3 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#4 0x00007f0134631190 in function_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#5 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#6 0x00007f01346b1956 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#7 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#8 0x00007f01346b5ab5 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#9 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#10 0x00007f01346b5ab5 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#11 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#12 0x00007f0134631265 in function_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#13 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#14 0x00007f01346b1956 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#15 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#16 0x00007f01346b5ab5 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#17 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#18 0x00007f0134631265 in function_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#19 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#20 0x00007f01346b1956 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#21 0x00007f01346b5b63 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#22 0x00007f01346b5b63 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#23 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#24 0x00007f0134631190 in function_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#25 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#26 0x00007f013460e21d in instancemethod_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#27 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#28 0x00007f013466ac6f in slot_tp_init () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#29 0x00007f01346697ef in type_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#30 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#31 0x00007f01346b2281 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#32 0x00007f01346b5b63 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#33 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#34 0x00007f01346b5ab5 in PyEval_EvalFrameEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#35 0x00007f01346b65cd in PyEval_EvalCodeEx () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#36 0x00007f0134631190 in function_call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#37 0x00007f01345ff793 in PyObject_Call () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#38 0x00007f01346aff67 in PyEval_CallObjectWithKeywords () from /opt/debesys/ext/linux/x86-64/release/lib/libpython2.7.so.1.0
#39 0x0000000000417299 in pybind11::detail::simple_collector<(pybind11::return_value_policy)1>::call(_object*) const ()
#40 0x0000000000413c48 in _ZNK8pybind116detail10object_apiINS0_8accessorINS0_17accessor_policies8str_attrEEEEclILNS_19return_value_policyE1EJEEENS_6objectEDpOT0_ ()
#41 0x00000000004054b7 in n_sim::Sim::Sim() ()
#42 0x00000000004055f5 in main ()
Any idea on what need to be done to cleanly run this program?
This was happening because some of the resources held by Python module were not getting released. Wrote python function stop in python module and called that in C++ at the end solved this issue.
Just before return I am now calling SimWrap->sim.attr("stop")();
I have a CppUnit test suite that I execute and at the end of the execution the application segments.
I have been trying to understand this core dump for a while now and I can't figure out what might be wrong, I though if I paste it here maybe someone would've encountered such issue and point me in a good direction.
Program terminated with signal 11, Segmentation fault.
#0 0x000000000100ad8e in CppUnit::XmlOutputter::XmlOutputter (this=0x7fffc180bc00, result=<optimized out>, stream=<optimized out>, encoding=...) at XmlOutputter.cpp:21
21 XmlOutputter.cpp: No such file or directory.
in XmlOutputter.cpp
(gdb) where
#0 0x000000000100ad8e in CppUnit::XmlOutputter::XmlOutputter (this=0x7fffc180bc00, result=<optimized out>, stream=<optimized out>, encoding=...) at XmlOutputter.cpp:21
#1 0x00000000016e7d18 in ?? ()
#2 0x0000000001426498 in std::string::_Rep::_S_empty_rep_storage ()
#3 0x000000000101488a in ?? ()
#4 0x00000000016d1de8 in ?? ()
#5 0x00000000016e79e0 in ?? ()
#6 0x00000000016e79f0 in ?? ()
#7 0x00000000016e79e8 in ?? ()
#8 0x00007f93740040e0 in ?? ()
#9 0x00007f9374001310 in ?? ()
#10 0x0000000000000004 in ?? ()
#11 0x00007fffc180bcf8 in ?? ()
#12 0x00007f93740040e0 in ?? ()
#13 0x00000000016e79e0 in ?? ()
#14 0x000000000100b1a2 in CppUnit::XmlOutputter::addSuccessfulTest (this=<optimized out>, test=0x7f9374004de0, testNumber=32767, testsNode=0x7f9374001610) at XmlOutputter.cpp:195
#15 0x00007f937c47bd85 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) () from /usr/lib64/libstdc++.so.6
#16 0x000000000100a887 in CppUnit::TextTestRunner::~TextTestRunner (this=<optimized out>, __in_chrg=<optimized out>) at TextTestRunner.cpp:36
#17 0x000000000100a4ca in __exchange_and_add_single (__val=<optimized out>, __mem=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/ext/atomicity.h:70
#18 __exchange_and_add_dispatch (__val=<optimized out>, __mem=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/ext/atomicity.h:86
#19 _M_dispose (__a=<optimized out>, this=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/basic_string.h:234
#20 ~basic_string (this=<optimized out>, __in_chrg=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/basic_string.h:494
#21 _Destroy<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__pointer=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/stl_construct.h:88
#22 _Destroy<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*> (__last=<optimized out>, __first=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/stl_construct.h:103
#23 _Destroy<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__last=<optimized out>, __first=0x0)
at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/stl_construct.h:128
#24 _M_destroy_data_aux (__last=<optimized out>, __first=<optimized out>, this=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/deque.tcc:709
#25 _M_destroy_data (__last=<optimized out>, __first=<optimized out>, this=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/stl_deque.h:1604
#26 ~deque (this=<optimized out>, __in_chrg=<optimized out>) at /proj/ims_lu/repository/LOTC/R1A07-0/usr/include/c++/4.3/bits/stl_deque.h:776
#27 ~Message (this=<optimized out>, __in_chrg=<optimized out>) at ../../include/cppunit/Message.h:39
#28 CppUnit::TextOutputter::printFailureDetail (this=0x407a80, thrownException=0x7fffc180d1b0) at TextOutputter.cpp:101
#29 0x00007f937c3e7b38 in ?? () from /usr/lib64/libstdc++.so.6
#30 0x00007fffc180bf50 in ?? ()
#31 0x00007fffc180c0b0 in ?? ()
#32 0x00007fffc180c0c8 in ?? ()
#33 0x00007f937d84f58b in _dl_map_object_deps () from /lib64/ld-linux-x86-64.so.2
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Just a guess, but try using the generic TestRunner with the XmlOutputter, not the TextTestRunner
CPPUNIT_NS::TextUi::TestRunner runner;
std::ofstream outputFile("testOutput.xml" );
CPPUNIT_NS::XmlOutputter xmlOutputter( &runner.result(), outputFile );
runner.addTest( testSuite );
runner.setOutputter( &xmlOutputter );
runner.run();
I have the following code taken right from libpng documentation:
Also if it is of any use this code is inside a class that is called from a gtkmm based application.
FILE *fp = fopen(path.c_str(), "rb");
if (!fp)
return false;
unsigned char sig[8];
fread(sig, 1, 8, fp);
if (!png_sig_cmp(sig, 0, 8))
return false;
I installed the debuginfo on, and ran gdb from the command line. I proceeded to step through the code to see why the png_sig_cmp() function is saying that the first 8 bits of a png that I created with GIMP and a few other .png files that I downloaded from the internet are not being recognized by png. I hope the output from gdb is more informative to you than it was to me:
...
_IO_fread (buf=<optimized out>, size=1, count=8, fp=0x848440) at iofread.c:43
43 _IO_acquire_lock (fp);
(gdb)
_IO_acquire_lock_fct (p=<optimized out>) at libioP.h:968
968 if ((fp->_flags & _IO_USER_LOCK) == 0)
(gdb)
969 _IO_funlockfile (fp);
(gdb)
_IO_fread (buf=<optimized out>, size=1, count=8, fp=0x848440) at iofread.c:46
46 return bytes_requested == bytes_read ? count : bytes_read / size;
(gdb)
47 }
(gdb)
PNGFileReader::read_png (this=0x7ca620, path=<optimized out>) at pngfilereader.cpp:46
46 if (!png_sig_cmp(sig, 0, 8))
(gdb) step
png_sig_cmp (sig=0x7fffffffd830 "\211PNG\r\n\032\n\236\330\377\377\377\177", start=0, num_to_check=8) at png.c:122
122 {
(gdb)
124 if (num_to_check > 8)
(gdb)
123 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
(gdb)
124 if (num_to_check > 8)
(gdb)
126 else if (num_to_check < 1)
(gdb)
127 return (-1);
(gdb)
126 else if (num_to_check < 1)
(gdb)
129 if (start > 7)
(gdb)
130 return (-1);
(gdb)
129 if (start > 7)
(gdb)
132 if (start + num_to_check > 8)
(gdb)
135 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
(gdb)
__memcmp_sse4_1 () at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:52
52 pxor %xmm0, %xmm0
(gdb)
53 cmp $79, %rdx
(gdb)
54 ja L(79bytesormore)
(gdb)
56 cmp $1, %rdx
(gdb)
57 je L(firstbyte)
(gdb)
59 add %rdx, %rsi
(gdb)
60 add %rdx, %rdi
(gdb)
61 BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
(gdb)
803 mov -8(%rdi), %rax
(gdb)
804 mov -8(%rsi), %rcx
(gdb)
805 cmp %rax, %rcx
(gdb)
806 jne L(diffin8bytes)
(gdb)
807 xor %eax, %eax
(gdb)
__memcmp_sse4_1 () at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:808
808 ret
(gdb)
png_sig_cmp (sig=<optimized out>, start=<optimized out>, num_to_check=<optimized out>) at png.c:136
136 }
(gdb)
PNGFileReader::read_png (this=0x7ca620, path=<optimized out>) at pngfilereader.cpp:47
47 return false;
(gdb)
46 if (!png_sig_cmp(sig, 0, 8))
The stack trace one returning from the png_sig_cmp function is
#0 PNGFileReader::read_png (this=0x7ca620, path=<optimized out>) at pngfilereader.cpp:46
#1 0x0000000000409017 in DrawingArea::zoom (this=0x7c8360, zoom_factor=<optimized out>) at drawingarea.cpp:97
#2 0x00000000004090cd in DrawingArea::on_scroll_event (this=<optimized out>, event=<optimized out>) at drawingarea.cpp:70
#3 0x000000351fd5cb03 in Gtk::Widget_Class::scroll_event_callback (self=0x6df8e0 [gtkmm__GtkDrawingArea], p0=0x7bf4b0) at widget.cc:4474
#4 0x000000351cf52848 in _gtk_marshal_BOOLEAN__BOXED (closure=0x62d640, return_value=0x7fffffffda80, n_param_values=<optimized out>, param_values=0x82da90,
invocation_hint=<optimized out>, marshal_data=<optimized out>) at gtkmarshalers.c:85
#5 0x0000003515a0ea24 in g_closure_invoke (closure=0x62d640, return_value=0x7fffffffda80, n_param_values=2, param_values=0x82da90, invocation_hint=<optimized out>)
at gclosure.c:774
#6 0x0000003515a20b5c in signal_emit_unlocked_R (node=<optimized out>, detail=0, instance=0x6df8e0, emission_return=0x7fffffffdbe0, instance_and_params=0x82da90)
at gsignal.c:3310
#7 0x0000003515a29f13 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=<optimized out>) at gsignal.c:3013
#8 0x0000003515a2a2e2 in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3060
#9 0x000000351d07eff9 in gtk_widget_event_internal (widget=0x6df8e0 [gtkmm__GtkDrawingArea], event=0x7bf4b0) at gtkwidget.c:6132
#10 0x000000351cf51fba in gtk_propagate_event (widget=0x6df8e0 [gtkmm__GtkDrawingArea], event=0x7bf4b0) at gtkmain.c:2614
#11 0x000000351cf523bb in gtk_main_do_event (event=0x7bf4b0) at gtkmain.c:1889
#12 0x000000351de47572 in gdk_event_source_dispatch (source=<optimized out>, callback=<optimized out>, user_data=<optimized out>) at gdkeventsource.c:360
#13 0x0000003514a44acd in g_main_dispatch (context=0x663aa0) at gmain.c:2441
#14 g_main_context_dispatch (context=0x663aa0) at gmain.c:3011
#15 0x0000003514a452c8 in g_main_context_iterate (context=0x663aa0, block=<optimized out>, dispatch=1, self=<optimized out>) at gmain.c:3089
#16 0x0000003514a45815 in g_main_loop_run (loop=0x8564c0) at gmain.c:3297
#17 0x000000351cf517fd in gtk_main () at gtkmain.c:1362
#18 0x000000351fcfd026 in Gtk::Main::run (window=...) at main.cc:384
#19 0x00000000004075f0 in main (argc=1, argv=0x7fffffffe168) at main.cpp:10
The problem seems to be the check of the return value from png_sig_cmp. Looking at the documentation, it seems this follows a memcmp return style, in other words, 0 is returned for a good header, nonzero for a non-match.
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.
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.
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.