]> granicus.if.org Git - python/commitdiff
Fix SF bug #474538: Memory (reference) leak in poller.register (Dave Brueck)
authorGuido van Rossum <guido@python.org>
Thu, 25 Oct 2001 20:18:35 +0000 (20:18 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 25 Oct 2001 20:18:35 +0000 (20:18 +0000)
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.)

Misc/ACKS
Modules/selectmodule.c

index 18bac30b7226e9e3ce3e7f3714ee33eedc75d2ad..f6b73fe3a0d6c2df67ee3ccf51111187f4bf314e 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -54,6 +54,7 @@ Terrence Brannon
 Dave Brennan
 Gary S. Brown
 Oleg Broytmann
+Dave Brueck
 Stan Bubrouski
 Erik de Bueger
 Jan-Hein B"uhrman
index e480fb47851728e10521cfc553a2ce381d91b5fd..348987b6030aa29210da4bf59eea5f78daa193bf 100644 (file)
@@ -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);