diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-25 09:10:21 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-25 09:10:21 (GMT) |
commit | 374164c2f5a2f95f74cc9b97d4b58d7c74ff3a94 (patch) | |
tree | 86b9585e0a740f49f10893c3aa5dc6337484ae07 /Modules | |
parent | 389e3d768d8f5bd312476db795f6432651bc656b (diff) | |
download | cpython-374164c2f5a2f95f74cc9b97d4b58d7c74ff3a94.zip cpython-374164c2f5a2f95f74cc9b97d4b58d7c74ff3a94.tar.gz cpython-374164c2f5a2f95f74cc9b97d4b58d7c74ff3a94.tar.bz2 |
Issue #14373: Fixed segmentation fault when gc.collect() is called during
constructing lru_cache (C implementation).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_functoolsmodule.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 95b5b13..dc64cfe 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -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; |