summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2011-10-24 18:12:58 (GMT)
committerPetri Lehtinen <petri@digip.org>2011-10-24 18:12:58 (GMT)
commita94200e6ce17d794c121cbeff7d9b61b206a2429 (patch)
treef972334b57a32368d0e82f4125526ffaff073f30 /Objects/dictobject.c
parentce770375031ad3c1b52097be464ce6bc758845a3 (diff)
downloadcpython-a94200e6ce17d794c121cbeff7d9b61b206a2429.zip
cpython-a94200e6ce17d794c121cbeff7d9b61b206a2429.tar.gz
cpython-a94200e6ce17d794c121cbeff7d9b61b206a2429.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.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 3fa5cc4..79894e5 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1314,14 +1314,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
PyObject *key;
Py_hash_t 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;
}
@@ -1332,14 +1336,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
PyObject *key;
Py_hash_t 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;
}