diff options
author | Petri Lehtinen <petri@digip.org> | 2011-10-24 17:59:29 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2011-10-24 17:59:29 (GMT) |
commit | 8ffbab8d02ca6aa925a8f339b71c6677b9c49fb6 (patch) | |
tree | 43e75eb20ac401f2068f8fbb29e7273f48e53e63 /Objects/dictobject.c | |
parent | c8065e46fed927b35310bddcc0adf8898ff9c784 (diff) | |
download | cpython-8ffbab8d02ca6aa925a8f339b71c6677b9c49fb6.zip cpython-8ffbab8d02ca6aa925a8f339b71c6677b9c49fb6.tar.gz cpython-8ffbab8d02ca6aa925a8f339b71c6677b9c49fb6.tar.bz2 |
Issue #13018: Fix reference leaks in error paths in dictobject.c.
Patch by Suman Saha.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e8f8b4a..f2ebf45 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1335,14 +1335,18 @@ dict_fromkeys(PyObject *cls, PyObject *args) PyObject *key; long hash; - if (dictresize(mp, Py_SIZE(seq))) + if (dictresize(mp, Py_SIZE(seq))) { + Py_DECREF(d); return NULL; + } while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) { Py_INCREF(key); Py_INCREF(value); - if (insertdict(mp, key, hash, value)) + if (insertdict(mp, key, hash, value)) { + Py_DECREF(d); return NULL; + } } return d; } @@ -1353,14 +1357,18 @@ dict_fromkeys(PyObject *cls, PyObject *args) PyObject *key; long hash; - if (dictresize(mp, PySet_GET_SIZE(seq))) + if (dictresize(mp, PySet_GET_SIZE(seq))) { + Py_DECREF(d); return NULL; + } while (_PySet_NextEntry(seq, &pos, &key, &hash)) { Py_INCREF(key); Py_INCREF(value); - if (insertdict(mp, key, hash, value)) + if (insertdict(mp, key, hash, value)) { + Py_DECREF(d); return NULL; + } } return d; } |