[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.129,2.130

Barry A. Warsaw python-dev@python.org
Thu, 13 Apr 2000 11:20:43 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Modules
In directory anthem:/home/bwarsaw/projects/python/Modules

Modified Files:
	posixmodule.c 
Log Message:
setup_confname_table(): Close memory leak caused by not decref'ing the
inserted dictionary values.  Also, simplified the logic a bit.


Index: posixmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.129
retrieving revision 2.130
diff -C2 -r2.129 -r2.130
*** posixmodule.c	2000/03/31 01:26:23	2.129
--- posixmodule.c	2000/04/13 15:20:40	2.130
***************
*** 4326,4350 ****
  {
      PyObject *d = NULL;
  
      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 (PyDict_SetItemString(moddict, tablename, d) == -1)
!             return -1;
!         return 0;
      }
!     return -1;
  }
  
--- 4326,4349 ----
  {
      PyObject *d = NULL;
+     size_t i;
+     int status;
  
      qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
      d = PyDict_New();
!     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;
              }
! 	    Py_DECREF(o);
      }
!     status = PyDict_SetItemString(moddict, tablename, d);
!     Py_DECREF(d);
!     return status;
  }