Edgewall Software

Ticket #166: cspeedups-fix-memleak-r780.2.diff

File cspeedups-fix-memleak-r780.2.diff, 2.2 KB (added by cboos, 13 months ago)

Updated version: this one fixes the leak. The major culprit appeared to be a missing DECREF for the PySequence?_GetItem in Markup_join, near line 269.

  • trunk/genshi/_speedups.c

     
    8787 
    8888    out = (PyUnicodeObject*) PyUnicode_FromUnicode(NULL, len); 
    8989    if (out == NULL) { 
     90        Py_DECREF((PyObject *) in); 
    9091        return NULL; 
    9192    } 
    9293 
     
    130131        inp++; 
    131132    } 
    132133 
     134    Py_DECREF((PyObject *) in); 
     135 
    133136    args = PyTuple_New(1); 
    134137    if (args == NULL) { 
    135138        Py_DECREF((PyObject *) out); 
     
    242245Markup_join(PyObject *self, PyObject *args, PyObject *kwds) 
    243246{ 
    244247    static char *kwlist[] = {"seq", "escape_quotes", 0}; 
    245     PyObject *seq = NULL, *seq2, *tmp; 
     248    PyObject *seq = NULL, *seq2, *tmp, *tmp2; 
    246249    char quotes = 1; 
    247250    int n, i; 
    248251 
     
    266269            Py_DECREF(seq2); 
    267270            return NULL; 
    268271        } 
    269         tmp = escape(tmp, quotes); 
    270         if (tmp == NULL) { 
     272        tmp2 = escape(tmp, quotes); 
     273        if (tmp2 == NULL) { 
    271274            Py_DECREF(seq2); 
    272275            return NULL; 
    273276        } 
    274         PyTuple_SET_ITEM(seq2, i, tmp); 
     277        PyTuple_SET_ITEM(seq2, i, tmp2); 
     278        Py_DECREF(tmp); 
    275279    } 
    276280    tmp = PyUnicode_Join(self, seq2); 
    277281    Py_DECREF(seq2); 
     
    303307            return NULL; 
    304308        tmp2 = PyUnicode_Concat(tmp, other); 
    305309    } 
    306     if (tmp2 == NULL) { 
    307         Py_DECREF(tmp); 
     310    Py_DECREF(tmp); 
     311    if (tmp2 == NULL) 
    308312        return NULL; 
    309     } 
    310     Py_DECREF(tmp); 
    311313    args = PyTuple_New(1); 
    312314    if (args == NULL) { 
    313315        Py_DECREF(tmp2); 
     
    380382        if (unicode == NULL) return NULL; 
    381383        result = PyNumber_Multiply(unicode, self); 
    382384    } 
     385    Py_DECREF(unicode); 
    383386 
    384387    if (result == NULL) return NULL; 
    385388    args = PyTuple_New(1); 
     
    402405    format = PyString_FromString("<Markup %r>"); 
    403406    if (format == NULL) return NULL; 
    404407    result = PyObject_Unicode(self); 
    405     if (result == NULL) return NULL; 
     408    if (result == NULL) { 
     409        Py_DECREF(format); 
     410        return NULL; 
     411    } 
    406412    args = PyTuple_New(1); 
    407413    if (args == NULL) { 
     414        Py_DECREF(format); 
    408415        Py_DECREF(result); 
    409416        return NULL; 
    410417    }