changeset: 97054:9c6d11d22801 parent: 97051:c53d24ee3963 parent: 97053:5345e5ce2eed user: Serhiy Storchaka date: Sat Jul 25 12:11:00 2015 +0300 files: Misc/NEWS description: Issue #14373: Fixed segmentation fault when gc.collect() is called during constructing lru_cache (C implementation). diff -r c53d24ee3963 -r 9c6d11d22801 Misc/NEWS --- a/Misc/NEWS Sat Jul 25 02:45:18 2015 +0200 +++ b/Misc/NEWS Sat Jul 25 12:11:00 2015 +0300 @@ -57,6 +57,9 @@ 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. diff -r c53d24ee3963 -r 9c6d11d22801 Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c Sat Jul 25 02:45:18 2015 +0200 +++ b/Modules/_functoolsmodule.c Sat Jul 25 12:11:00 2015 +0300 @@ -899,7 +899,7 @@ 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 @@ 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;