[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    Re: [C++-sig] free() of null-pointing handle<> throws SIGABRT
From:       Martin Hellmich <mhellmic () cern ! ch>
Date:       2012-11-29 9:28:04
Message-ID: 50B72AA4.4060808 () cern ! ch
[Download RAW message or body]

Hi,

more investigation (single-stepping in gdb) lead to the discovery that 
the abrt comes from this line:
(gdb)
test-replicas: Objects/frameobject.c:633: PyFrame_New: Assertion 
`f->f_code == code' failed.
.EE.
Program received signal SIGABRT, Aborted.

The complete stacktrace is this:
(gdb) bt
#0  0x0000003a3a2328a5 in raise () from /lib64/libc.so.6
#1  0x0000003a3a234085 in abort () from /lib64/libc.so.6
#2  0x0000003a3a22ba1e in __assert_fail_base () from /lib64/libc.so.6
#3  0x0000003a3a22bae0 in __assert_fail () from /lib64/libc.so.6
#4  0x0000003a4c26deeb in PyFrame_New () from /usr/lib64/libpython2.6.so.1.0
#5  0x0000003a4c2dfee9 in PyEval_EvalCodeEx () from 
/usr/lib64/libpython2.6.so.1.0
#6  0x0000003a4c26edb0 in ?? () from /usr/lib64/libpython2.6.so.1.0
#7  0x0000003a4c244303 in PyObject_Call () from 
/usr/lib64/libpython2.6.so.1.0
#8  0x0000003a4c25970f in ?? () from /usr/lib64/libpython2.6.so.1.0
#9  0x0000003a4c244303 in PyObject_Call () from 
/usr/lib64/libpython2.6.so.1.0
#10 0x0000003a4c2d8dd3 in PyEval_CallObjectWithKeywords () from 
/usr/lib64/libpython2.6.so.1.0
#11 0x0000003a4c2f835a in PyEval_CallFunction () from 
/usr/lib64/libpython2.6.so.1.0
#12 0x00007ffff79529e6 in 
boost::python::call<boost::python::api::object, unsigned long, 
std::basic_string<char, std::char_traits<char>, std::allocator<char>
  > > (callable=0x7ffff78f0fa0, a0=<value optimized out>, a1=<value 
optimized out>) at /usr/include/boost/python/call.hpp:66
#13 0x00007ffff795000e in operator()<ino_t, std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > > (this=<value optimized 
out>, parent=0,
     name="/") at /usr/include/boost/python/object_call.hpp:19
#14 dmlite::PythonINode::extendedStat (this=<value optimized out>, 
parent=0, name="/")
     at 
/usr/src/debug/dmlite-0.6.0/python/embedding/src/cpp/PythonINode.cpp:171
#15 0x0000003ab0a63a09 in dmlite::BuiltInCatalog::extendedStat 
(this=0x724640, path=<value optimized out>, followSym=true)
     at /usr/src/debug/dmlite-0.6.0/src/core/builtin/Catalog.cpp:149
#16 0x0000003ab0a60d64 in dmlite::BuiltInCatalog::changeDir 
(this=0x724640, path="/") at 
/usr/src/debug/dmlite-0.6.0/src/core/builtin/Catalog.cpp:116
#17 0x0000000000406b4b in TestReplicas::setUp (this=0x620540) at 
/usr/src/debug/dmlite-0.6.0/tests/cpp/test-replicas.cpp:16
#18 0x0000003a3ce24d3a in CppUnit::TestCaseMethodFunctor::operator()() 
const () from /usr/lib64/libcppunit-1.12.so.1
#19 0x0000003a3ce1a064 in 
CppUnit::DefaultProtector::protect(CppUnit::Functor const&, 
CppUnit::ProtectorContext const&) ()
    from /usr/lib64/libcppunit-1.12.so.1
#20 0x0000003a3ce21647 in 
CppUnit::ProtectorChain::protect(CppUnit::Functor const&, 
CppUnit::ProtectorContext const&) ()
    from /usr/lib64/libcppunit-1.12.so.1
#21 0x0000003a3ce2a834 in CppUnit::TestResult::protect(CppUnit::Functor 
const&, CppUnit::Test*, std::basic_string<char, std::char_traits<char>, 
std::allocato
r<char> > const&) () from /usr/lib64/libcppunit-1.12.so.1
#22 0x0000003a3ce24989 in CppUnit::TestCase::run(CppUnit::TestResult*) 
() from /usr/lib64/libcppunit-1.12.so.1
#23 0x0000003a3ce250c3 in 
CppUnit::TestComposite::doRunChildTests(CppUnit::TestResult*) () from 
/usr/lib64/libcppunit-1.12.so.1
#24 0x0000003a3ce24fe6 in 
CppUnit::TestComposite::run(CppUnit::TestResult*) () from 
/usr/lib64/libcppunit-1.12.so.1
#25 0x0000003a3ce250c3 in 
CppUnit::TestComposite::doRunChildTests(CppUnit::TestResult*) () from 
/usr/lib64/libcppunit-1.12.so.1
#26 0x0000003a3ce24fe6 in 
CppUnit::TestComposite::run(CppUnit::TestResult*) () from 
/usr/lib64/libcppunit-1.12.so.1
#27 0x0000003a3ce2a5da in CppUnit::TestResult::runTest(CppUnit::Test*) 
() from /usr/lib64/libcppunit-1.12.so.1
#28 0x0000003a3ce2c553 in CppUnit::TestRunner::run(CppUnit::TestResult&, 
std::basic_string<char, std::char_traits<char>, std::allocator<char> > 
const&) ()
    from /usr/lib64/libcppunit-1.12.so.1
#29 0x0000003a3ce2ea2b in 
CppUnit::TextTestRunner::run(std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, bool, bool, bool) ()
    from /usr/lib64/libcppunit-1.12.so.1
#30 0x000000000040ef84 in testBaseMain (argn=<value optimized out>, 
argv=<value optimized out>) at 
/usr/src/debug/dmlite-0.6.0/tests/cpp/test-base.cpp:92
#31 0x0000003a3a21ecdd in __libc_start_main () from /lib64/libc.so.6
#32 0x00000000004063c9 in _start ()




On 11/23/2012 08:36 PM, Martin Hellmich wrote:
> Hi,
>
> in my exception handling (based on a tutorial, which I can dig up if it
> helps), I create handles for the exc, val, tb values of an exception
> thrown in python.
> The code is shown below in extractException(). It is a shortened
> version, which does not cover all possible cases.
>
> In some cases, val is defined, but tb is not. When then htb points to
> 0x0, the function fails with a SIGABRT as it returns.
> I believe that the free() for the htb fails, when it goes out of scope
> at the end of the function.
>
> I put the Error message and the GDB output at the end of the mail.
> The address at which the free() fails is likely the one of tb, as it
> sits inbetween exc and val in memory.
>
> Other calls to extractException() where tb is not null do not abort.
>
> Do you have an idea why the free() could fail?
> I am happy to post more information, if needed and would welcome any
> hints :)
>
> Cheers
> Martin
>
> void PythonExceptionHandler::extractException() throw (DmException)
> {
>    using namespace boost::python;
>
>    PyObject *exc,*val,*tb;
>    PyErr_Fetch(&exc,&val,&tb);
>    PyErr_NormalizeException(&exc,&val,&tb);
>    handle<> hexc(exc),hval(allow_null(val)),htb(allow_null(tb));
>
>    int code = 0;
>    std::string what = "";
>
>    if (PyObject_HasAttrString(val, "code") &&
> PyObject_HasAttrString(val, "what")) {
>      object oval(hval);
>      extract<int> get_code(oval.attr("code")());
>      extract<std::string> get_what(oval.attr("what")());
>      code = get_code();
>      what = get_what();
>      throw DmException(code, what);
>    } else {
>      std::string excString;
>      excString = extract<std::string>(str(hexc));
>      throw DmException(DMLITE_SYSERR(DMLITE_UNKNOWN_ERROR),
>                      excString);
>    }
> }
>
> Error Message:
> *** glibc detected *** /usr/lib64/dmlite/test/cpp/test-replicas: free():
> invalid pointer: 0x0000003a4c5a0d60 ***
>
> GDB output:
> (gdb) p htb
> $6 = {m_p = 0x0}
> (gdb) p tb
> $7 = (PyObject *) 0x0
> (gdb) info locals
> val = 0x3a4c5a0d80
> tb = 0x0
> hexc = {m_p = 0x3a4c579ea0}
> what = ""
> exc = 0x3a4c579ea0
> hval = {m_p = 0x3a4c5a0d80}
> htb = {m_p = 0x0}
> code = <value optimized out>
>

-- 
Martin Hellmich                    Information Technology Department
mhellmic@cern.ch                                                CERN
+41 22 76 765 26                                   CH-1211 Geneva 23
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic