Commit e90d5aab authored by Tim Peters's avatar Tim Peters

SF patch #413552 - Premature decref on object

Jeffery Collins pointed out that filterstring decrefs a character object
before it's done using it.  This works by accident today because another
module always happens to have an active reference too at the time.  The
accident doesn't work after his Pippy modifications, and since it *is*
an accident even in the mainline Python, it should work by design there too.
The patch accomplishes that.
parent 3aa480bc
...@@ -2291,18 +2291,22 @@ filterstring(PyObject *func, PyObject *strobj) ...@@ -2291,18 +2291,22 @@ filterstring(PyObject *func, PyObject *strobj)
if (item == NULL) if (item == NULL)
goto Fail_1; goto Fail_1;
arg = Py_BuildValue("(O)", item); arg = Py_BuildValue("(O)", item);
Py_DECREF(item); if (arg == NULL) {
if (arg == NULL) Py_DECREF(item);
goto Fail_1; goto Fail_1;
}
good = PyEval_CallObject(func, arg); good = PyEval_CallObject(func, arg);
Py_DECREF(arg); Py_DECREF(arg);
if (good == NULL) if (good == NULL) {
Py_DECREF(item);
goto Fail_1; goto Fail_1;
}
ok = PyObject_IsTrue(good); ok = PyObject_IsTrue(good);
Py_DECREF(good); Py_DECREF(good);
if (ok) if (ok)
PyString_AS_STRING((PyStringObject *)result)[j++] = PyString_AS_STRING((PyStringObject *)result)[j++] =
PyString_AS_STRING((PyStringObject *)item)[0]; PyString_AS_STRING((PyStringObject *)item)[0];
Py_DECREF(item);
} }
if (j < len && _PyString_Resize(&result, j) < 0) if (j < len && _PyString_Resize(&result, j) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment