diff options
author | Guido van Rossum <guido@python.org> | 2001-10-25 20:18:35 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-25 20:18:35 +0000 |
commit | a0dfc8577de8c1b6de19dccc2992b6d95b71f969 (patch) | |
tree | 868bbe82dc0fffabb96ef5b91a2647733c07da57 /Modules/selectmodule.c | |
parent | b112481f128030f4627828287a98b38d9c7780f0 (diff) | |
download | cpython-git-a0dfc8577de8c1b6de19dccc2992b6d95b71f969.tar.gz |
Fix SF bug #474538: Memory (reference) leak in poller.register (Dave Brueck)
Replace some tortuous code that was trying to be clever but forgot to
DECREF the key and value, by more longwinded but obviously correct
code.
(Inspired by but not copying the fix from SF patch #475033.)
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r-- | Modules/selectmodule.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index e480fb4785..348987b603 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -366,6 +366,7 @@ poll_register(pollObject *self, PyObject *args) { PyObject *o, *key, *value; int fd, events = POLLIN | POLLPRI | POLLOUT; + int err; if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) { return NULL; @@ -376,11 +377,20 @@ poll_register(pollObject *self, PyObject *args) /* Add entry to the internal dictionary: the key is the file descriptor, and the value is the event mask. */ - if ( (NULL == (key = PyInt_FromLong(fd))) || - (NULL == (value = PyInt_FromLong(events))) || - (PyDict_SetItem(self->dict, key, value)) == -1) { + key = PyInt_FromLong(fd); + if (key == NULL) + return NULL; + value = PyInt_FromLong(events); + if (value == NULL) { + Py_DECREF(key); return NULL; } + err = PyDict_SetItem(self->dict, key, value); + Py_DECREF(key); + Py_DECREF(value); + if (err < 0) + return NULL; + self->ufd_uptodate = 0; Py_INCREF(Py_None); |