[Python-checkins] CVS: python/dist/src/Modules selectmodule.c,2.50.4.4,2.50.4.5

Anthony Baxter anthonybaxter@users.sourceforge.net
Thu, 01 Nov 2001 06:43:53 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv11223

Modified Files:
      Tag: release21-maint
	selectmodule.c 
Log Message:
backport of 2.58:
  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.


Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.50.4.4
retrieving revision 2.50.4.5
diff -C2 -d -r2.50.4.4 -r2.50.4.5
*** selectmodule.c	2001/11/01 14:39:41	2.50.4.4
--- selectmodule.c	2001/11/01 14:43:51	2.50.4.5
***************
*** 373,376 ****
--- 373,377 ----
  	PyObject *o, *key, *value;
  	int fd, events = POLLIN | POLLPRI | POLLOUT;
+ 	int err;
  
  	if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) {
***************
*** 383,391 ****
  	/* 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) {
  		return NULL;
  	}
  	self->ufd_uptodate = 0;
  		       
--- 384,401 ----
  	/* Add entry to the internal dictionary: the key is the 
  	   file descriptor, and the value is the event mask. */
! 	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;