]> granicus.if.org Git - python/commitdiff
Issue #3660 (part of): fix a memory leak in _pickle.
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 5 Sep 2008 00:03:33 +0000 (00:03 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 5 Sep 2008 00:03:33 +0000 (00:03 +0000)
Patch by Amaury Forgeot d'Arc, review by me.

Misc/NEWS
Modules/_pickle.c

index 889cead8a693f7c00b5203ab5e6808768302c939..1bb4f6f4f91a0b926ce2d13a3e89ad16f713ebfb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -80,6 +80,8 @@ C API
 Library
 -------
 
+- Issue #3660: fix a memory leak in the C accelerator of the pickle module.
+
 - Issue #3160: the "bdist_wininst" distutils command didn't work.
 
 - Issue #1658: tkinter changes dict size during iteration in both
index ea5bbe2759aa9a0e7945df6534109c3c565a854e..f7b5212863881aabe8a276b952350a351617128d 100644 (file)
@@ -3837,13 +3837,17 @@ load_build(UnpicklerObject *self)
     if (setstate == NULL) {
         if (PyErr_ExceptionMatches(PyExc_AttributeError))
             PyErr_Clear();
-        else
+        else {
+            Py_DECREF(state);
             return -1;
+        }
     }
     else {
         PyObject *result;
 
         /* The explicit __setstate__ is responsible for everything. */
+        /* Ugh... this does not leak since unpickler_call() steals the
+           reference to state first. */
         result = unpickler_call(self, setstate, state);
         Py_DECREF(setstate);
         if (result == NULL)