[Zodb-checkins] CVS: StandaloneZODB/ZODB - cPersistence.c:1.46

Barry Warsaw barry@wooz.org
Thu, 8 Nov 2001 12:12:03 -0500


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv7515/ZODB

Modified Files:
	cPersistence.c 
Log Message:
initcPersistence(): Some cleanup of the initializer.  First be sure to
decref the revision string, added to the module dict with the keys
"__version__".  Do the same with the PyCObject set to the dict's
"CAPI" key.  This fixes small leaks detected by Insure.

Also, clean up the way the global TimeStamp static is handled on
creation failure.  We need to decref `s' whether or not TimeStamp was
properly created or not.  Also, at the end of the function, we do a
PyErr_Occurred() check and throw a fatal error if true.  This makes
this module's init function more in line with other init functions in
this package.


=== StandaloneZODB/ZODB/cPersistence.c 1.45 => 1.46 ===
   TimeStamp = PyObject_GetAttr(m, s);
   Py_DECREF(m);
-  if (TimeStamp == NULL) {
-      Py_DECREF(s);
-  }
+  Py_DECREF(s);
 
   if (init_strings() < 0) return;
 
@@ -783,12 +781,19 @@
 
   
   d = PyModule_GetDict(m);
-  PyDict_SetItemString(d,"__version__",
-		       PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));
+  s = PyString_FromStringAndSize(rev+11,strlen(rev+11)-2);
+  PyDict_SetItemString(d,"__version__", s);
+  Py_XDECREF(s);
+
   PyExtensionClass_Export(d, "Persistent",  Pertype);
   PyExtensionClass_Export(d, "Overridable", Overridable);
 
   cPersistenceCAPI=&truecPersistenceCAPI;
-  PyDict_SetItemString(d, "CAPI",
-		       PyCObject_FromVoidPtr(cPersistenceCAPI,NULL));
+  s = PyCObject_FromVoidPtr(cPersistenceCAPI,NULL);
+  PyDict_SetItemString(d, "CAPI", s);
+  Py_XDECREF(s);
+
+  /* Check for errors */
+  if (PyErr_Occurred())
+    Py_FatalError("can't initialize module cPersistence");
 }