Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a94200e

Browse files
committed
Issue #13018: Fix reference leaks in error paths in dictobject.c.
Patch by Suman Saha.
1 parent ce77037 commit a94200e

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13018: Fix reference leaks in error paths in dictobject.c.
14+
Patch by Suman Saha.
15+
1316
- Issue #1294232: In a few cases involving metaclass inheritance, the
1417
interpreter would sometimes invoke the wrong metaclass when building a new
1518
class object. These cases now behave correctly. Patch by Daniel Urban.

Objects/dictobject.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,14 +1314,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
13141314
PyObject *key;
13151315
Py_hash_t hash;
13161316

1317-
if (dictresize(mp, Py_SIZE(seq)))
1317+
if (dictresize(mp, Py_SIZE(seq))) {
1318+
Py_DECREF(d);
13181319
return NULL;
1320+
}
13191321

13201322
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
13211323
Py_INCREF(key);
13221324
Py_INCREF(value);
1323-
if (insertdict(mp, key, hash, value))
1325+
if (insertdict(mp, key, hash, value)) {
1326+
Py_DECREF(d);
13241327
return NULL;
1328+
}
13251329
}
13261330
return d;
13271331
}
@@ -1332,14 +1336,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
13321336
PyObject *key;
13331337
Py_hash_t hash;
13341338

1335-
if (dictresize(mp, PySet_GET_SIZE(seq)))
1339+
if (dictresize(mp, PySet_GET_SIZE(seq))) {
1340+
Py_DECREF(d);
13361341
return NULL;
1342+
}
13371343

13381344
while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
13391345
Py_INCREF(key);
13401346
Py_INCREF(value);
1341-
if (insertdict(mp, key, hash, value))
1347+
if (insertdict(mp, key, hash, value)) {
1348+
Py_DECREF(d);
13421349
return NULL;
1350+
}
13431351
}
13441352
return d;
13451353
}

0 commit comments

Comments
 (0)