]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport Tim's checkin 2.218:
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Mar 2003 14:36:50 +0000 (14:36 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Mar 2003 14:36:50 +0000 (14:36 +0000)
    slot_sq_contains():  This leaked a reference to the result of calling
    __contains__().

Objects/typeobject.c

index ad30f8e05c102854c8fec47e4d1231799c6fcd16..b674c337783cb13c59b99bb3badc691160003924 100644 (file)
@@ -3025,10 +3025,11 @@ static int
 slot_sq_contains(PyObject *self, PyObject *value)
 {
        PyObject *func, *res, *args;
+       int result = -1;
+
        static PyObject *contains_str;
 
        func = lookup_maybe(self, "__contains__", &contains_str);
-
        if (func != NULL) {
                args = Py_BuildValue("(O)", value);
                if (args == NULL)
@@ -3038,16 +3039,16 @@ slot_sq_contains(PyObject *self, PyObject *value)
                        Py_DECREF(args);
                }
                Py_DECREF(func);
-               if (res == NULL)
-                       return -1;
-               return PyObject_IsTrue(res);
+               if (res != NULL) {
+                       result = PyObject_IsTrue(res);
+                       Py_DECREF(res);
+               }
        }
-       else if (PyErr_Occurred())
-               return -1;
-       else {
-               return _PySequence_IterSearch(self, value,
-                                             PY_ITERSEARCH_CONTAINS);
+       else if (! PyErr_Occurred()) {
+               result = _PySequence_IterSearch(self, value,
+                                                PY_ITERSEARCH_CONTAINS);
        }
+       return result;
 }
 
 SLOT1(slot_sq_inplace_concat, "__iadd__", PyObject *, "O")