]> granicus.if.org Git - python/commitdiff
Issue #14373: Fixed segmentation fault when gc.collect() is called during
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 25 Jul 2015 09:10:21 +0000 (12:10 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 25 Jul 2015 09:10:21 +0000 (12:10 +0300)
constructing lru_cache (C implementation).

Misc/NEWS
Modules/_functoolsmodule.c

index d8922be945e4b2eaed9a24ac98fd0c97c002f63e..508572a5ffeb67156376198da8741cfbb3710307 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14373: Fixed segmentation fault when gc.collect() is called during
+  constructing lru_cache (C implementation).
+
 - Issue #24695: Fix a regression in traceback.print_exception().  If
   exc_traceback is None we shouldn't print a traceback header like described
   in the documentation.
index 95b5b13fbecad311d74fddf2deb3dd7be92f4e25..dc64cfee2df9f88fb5f48749f415e6f76bfad40e 100644 (file)
@@ -899,7 +899,7 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
 static PyObject *
 lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
 {
-    PyObject *func, *maxsize_O, *cache_info_type;
+    PyObject *func, *maxsize_O, *cache_info_type, *cachedict;
     int typed;
     lru_cache_object *obj;
     Py_ssize_t maxsize;
@@ -937,15 +937,16 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
         return NULL;
     }
 
-    obj = (lru_cache_object *)type->tp_alloc(type, 0);
-    if (obj == NULL)
+    if (!(cachedict = PyDict_New()))
         return NULL;
 
-    if (!(obj->cache = PyDict_New())) {
-        Py_DECREF(obj);
+    obj = (lru_cache_object *)type->tp_alloc(type, 0);
+    if (obj == NULL) {
+        Py_DECREF(cachedict);
         return NULL;
     }
 
+    obj->cache = cachedict;
     obj->root.prev = &obj->root;
     obj->root.next = &obj->root;
     obj->maxsize = maxsize;