mirror of
https://github.com/python/cpython.git
synced 2025-11-13 07:26:31 +00:00
setup_confname_table(): Close memory leak caused by not decref'ing the
inserted dictionary values. Also, simplified the logic a bit.
This commit is contained in:
parent
8deecedc6d
commit
3155db3b79
1 changed files with 14 additions and 15 deletions
|
|
@ -4325,27 +4325,26 @@ setup_confname_table(table, tablesize, tablename, moddict)
|
||||||
PyObject *moddict;
|
PyObject *moddict;
|
||||||
{
|
{
|
||||||
PyObject *d = NULL;
|
PyObject *d = NULL;
|
||||||
|
size_t i;
|
||||||
|
int status;
|
||||||
|
|
||||||
qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
|
qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
|
||||||
d = PyDict_New();
|
d = PyDict_New();
|
||||||
if (d != NULL) {
|
if (d == NULL)
|
||||||
PyObject *o;
|
return -1;
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
for (; i < tablesize; ++i) {
|
for (i=0; i < tablesize; ++i) {
|
||||||
o = PyInt_FromLong(table[i].value);
|
PyObject *o = PyInt_FromLong(table[i].value);
|
||||||
if (o == NULL
|
if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
|
||||||
|| PyDict_SetItemString(d, table[i].name, o) == -1) {
|
Py_XDECREF(o);
|
||||||
Py_DECREF(d);
|
Py_DECREF(d);
|
||||||
d = NULL;
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
Py_DECREF(o);
|
||||||
if (PyDict_SetItemString(moddict, tablename, d) == -1)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return -1;
|
status = PyDict_SetItemString(moddict, tablename, d);
|
||||||
|
Py_DECREF(d);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return -1 on failure, 0 on success. */
|
/* Return -1 on failure, 0 on success. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue