]> granicus.if.org Git - python/commitdiff
bpo-32013: _pickle: Add missing Py_DECREF in error case in fast_save_enter() (#4384)
authorMat M <mathew1800@gmail.com>
Mon, 13 Nov 2017 07:50:16 +0000 (02:50 -0500)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 13 Nov 2017 07:50:16 +0000 (09:50 +0200)
Modules/_pickle.c

index b71fb9350e62b300ade62a3d9452d47b3b4e3200..4b7f1ed66b30e9e13022a62131c7a49d6b40b259 100644 (file)
@@ -1777,8 +1777,10 @@ fast_save_enter(PicklerObject *self, PyObject *obj)
             }
         }
         key = PyLong_FromVoidPtr(obj);
-        if (key == NULL)
+        if (key == NULL) {
+            self->fast_nesting = -1;
             return 0;
+        }
         if (PyDict_GetItemWithError(self->fast_memo, key)) {
             Py_DECREF(key);
             PyErr_Format(PyExc_ValueError,
@@ -1789,6 +1791,8 @@ fast_save_enter(PicklerObject *self, PyObject *obj)
             return 0;
         }
         if (PyErr_Occurred()) {
+            Py_DECREF(key);
+            self->fast_nesting = -1;
             return 0;
         }
         if (PyDict_SetItem(self->fast_memo, key, Py_None) < 0) {