summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2000-04-13 15:20:40 (GMT)
committerBarry Warsaw <barry@python.org>2000-04-13 15:20:40 (GMT)
commit3155db3b793d384054abd586bcd42e8d4f5061da (patch)
treefe0f2882c84ac50bcd28539a8872f0f07c20f09c /Modules
parent8deecedc6d4b4c7cb914ad0220c3db0ef33dc8d8 (diff)
downloadcpython-3155db3b793d384054abd586bcd42e8d4f5061da.zip
cpython-3155db3b793d384054abd586bcd42e8d4f5061da.tar.gz
cpython-3155db3b793d384054abd586bcd42e8d4f5061da.tar.bz2
setup_confname_table(): Close memory leak caused by not decref'ing the
inserted dictionary values. Also, simplified the logic a bit.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 0ce2dfa..c948b95 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4325,27 +4325,26 @@ setup_confname_table(table, tablesize, tablename, moddict)
PyObject *moddict;
{
PyObject *d = NULL;
+ size_t i;
+ int status;
qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
d = PyDict_New();
- if (d != NULL) {
- PyObject *o;
- size_t i = 0;
-
- for (; i < tablesize; ++i) {
- o = PyInt_FromLong(table[i].value);
- if (o == NULL
- || PyDict_SetItemString(d, table[i].name, o) == -1) {
- Py_DECREF(d);
- d = NULL;
- return -1;
+ if (d == NULL)
+ return -1;
+
+ for (i=0; i < tablesize; ++i) {
+ PyObject *o = PyInt_FromLong(table[i].value);
+ if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
+ Py_XDECREF(o);
+ Py_DECREF(d);
+ return -1;
}
- }
- if (PyDict_SetItemString(moddict, tablename, d) == -1)
- return -1;
- return 0;
+ Py_DECREF(o);
}
- return -1;
+ status = PyDict_SetItemString(moddict, tablename, d);
+ Py_DECREF(d);
+ return status;
}
/* Return -1 on failure, 0 on success. */