[egenix-users] SIGSEGV in mxTextTools when using AppendToTagobj

M.-A. Lemburg mal at egenix.com
Thu May 17 13:55:27 CEST 2012


RICHARD MOSELEY wrote:
> I have just been spending time compiling the mxTextTools library into the
> latest version of the SimpleParse package in a python 2.7.3 virtualenv. The
> original packaged mxTextTools was 2.1.0 from 2003, so I decided to use the
> latest 3.2.4 package instead; after making all the appropriate changes and
> compiling, I then ran the test suite that is in the SimpleParse package,
> after running a few of the test the program failed with a SIGSEGV.
> 
> I tracked down the problem test to the testAppendToTagobj1 test in the
> mx_flag.py suite of tests and more specifically the testAppendToTagobj1
> test, I took the test out of the test suite and created a simple test file
> as follows:
> 
> from simpleparse.stt.TextTools import *
> class Test(object):
>   worked = ""
>   def append(self, value):
>     worked = value
> tagobj = Test()
> result = tag('abbaabccd',((tagobj,AllIn+AppendToTagobj,'ab',0),),0)
> print result
> 
> When this is run from within the virtualenv I got the following error:
> 
> (oratools)rmos at spot$ python /tmp/chktext.py
> Fatal Python error: stt/TextTools/mxTextTools/mxte_impl.h:1301 object at
> 0x242f5b0 has negative ref count -1
> 
> Reviewing the code around the stated line 1301 in mxte_impl.h gives the
> following code within the TE_HANDLE_MATCH function:
> 
> if (flags & MATCH_APPENDTAG) {
> ...
>         if (PyList_Check(tagobj)) {
>             if (PyList_Append(tagobj, w)) {
>                 Py_DECREF(w);
>                 goto onError;
>             }
>         }
>         else {
>             PyObject *result;
>             result = PyEval_CallMethod(tagobj, "append", "(O)", w);
>             Py_DECREF(w);
>             if (result == NULL)
>                 goto onError;
>             Py_DECREF(result);
>         }
>         Py_DECREF(w);   <-- INCORRECT
>         return 0;
>     }
> ...
> The problem with the code is that in the case of the tag object not beign a
> list the temporary 'w' object is DECREF'ed twice if the append is
> successful.
> 
> I commented out the extra call of Py_DECREF(w) and reran the test script,
> and it returned:
> 
> (oratools)rmos at spot2: python /tmp/chktext.py
> (1, [], 6)
> 
> which is what is by the original test.
> 
> I though that I should share this with you, in the hope that this will
> remove at least one cause of SIGSEGV in the mxTextTools package.

Thank you very much for the comprehensive bug report and excellent
analysis.

We will fix this problem in the next patch level release of eGenix mx Base.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 17 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2012-07-02: EuroPython 2012, Florence, Italy               46 days to go
2012-05-16: Released eGenix pyOpenSSL 0.13        http://egenix.com/go29
2012-04-26: Released mxODBC 3.1.2                 http://egenix.com/go28
2012-04-25: Released eGenix mx Base 3.2.4         http://egenix.com/go27

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/



More information about the egenix-users mailing list