]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport of 2.58:
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 1 Nov 2001 14:43:51 +0000 (14:43 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 1 Nov 2001 14:43:51 +0000 (14:43 +0000)
  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.

Modules/selectmodule.c

index 412bb8d690cb9a5cbbcee24712245f21d5db61e9..5eb4dc3dae8dd1701bb4b9bf7e81da36309aa866 100644 (file)
@@ -372,6 +372,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;
@@ -382,11 +383,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);