[Python-checkins] python/dist/src/Modules pyexpat.c,2.57.6.5,2.57.6.6

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Thu, 06 Mar 2003 08:28:04 -0800


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

Modified Files:
      Tag: release22-maint
	pyexpat.c 
Log Message:
Backport patch from revision 2.90:
Fix memory leak: free memory storing the content model passed to the
ElementDeclHandler by Expat.
Fixes SF bug #676990.


Index: pyexpat.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pyexpat.c,v
retrieving revision 2.57.6.5
retrieving revision 2.57.6.6
diff -C2 -d -r2.57.6.5 -r2.57.6.6
*** pyexpat.c	19 Jan 2003 15:48:38 -0000	2.57.6.5
--- pyexpat.c	6 Mar 2003 16:27:58 -0000	2.57.6.6
***************
*** 648,680 ****
  }
  
! static PyObject *
! conv_content_model_utf8(XML_Content * const model)
  {
!     return conv_content_model(model, conv_string_to_utf8);
! }
  
! #ifdef Py_USING_UNICODE
! static PyObject *
! conv_content_model_unicode(XML_Content * const model)
! {
!     return conv_content_model(model, conv_string_to_unicode);
! }
  
! VOID_HANDLER(ElementDecl,
!              (void *userData,
!               const XML_Char *name,
!               XML_Content *model),
!              ("O&O&",
!               STRING_CONV_FUNC,name,
!               (self->returns_unicode ? conv_content_model_unicode
!                                      : conv_content_model_utf8),model))
  #else
! VOID_HANDLER(ElementDecl,
!              (void *userData,
!               const XML_Char *name,
!               XML_Content *model),
!              ("O&O&",
!               STRING_CONV_FUNC,name, conv_content_model_utf8,model))
  #endif
  
  VOID_HANDLER(AttlistDecl,
--- 648,708 ----
  }
  
! static void
! my_ElementDeclHandler(void *userData,
!                       const XML_Char *name,
!                       XML_Content *model)
  {
!     xmlparseobject *self = (xmlparseobject *)userData;
!     PyObject *args = NULL;
  
!     if (self->handlers[ElementDecl] != NULL
!         && self->handlers[ElementDecl] != Py_None) {
!         PyObject *rv = NULL;
!         PyObject *modelobj, *nameobj;
  
! #ifdef Py_USING_UNICODE
!         modelobj = conv_content_model(model,
!                                       (self->returns_unicode
!                                        ? conv_string_to_unicode
!                                        : conv_string_to_utf8));
  #else
!         modelobj = conv_content_model(model, conv_string_to_utf8);
! #endif
!         if (modelobj == NULL) {
!             flag_error(self);
!             goto finally;
!         }
!         nameobj = PyString_FromString(name);
!         if (nameobj == NULL) {
!             Py_DECREF(modelobj);
!             flag_error(self);
!             goto finally;
!         }
!         args = Py_BuildValue("NN", nameobj, modelobj);
!         if (args == NULL) {
!             Py_DECREF(modelobj);
!             flag_error(self);
!             goto finally;
!         }
!         self->in_callback = 1;
!         rv = call_with_frame(getcode(ElementDecl, "ElementDecl", __LINE__),
!                              self->handlers[ElementDecl], args);
!         self->in_callback = 0;
!         if (rv == NULL) {
!             flag_error(self);
!             goto finally;
!         }
!         Py_DECREF(rv);
!     }
!  finally:
!     Py_XDECREF(args);
!     /* XML_FreeContentModel() was introduced in Expat 1.95.6. */
! #if EXPAT_VERSION >= 0x015f06
!     XML_FreeContentModel(self->itself, model);
! #else
!     free(model);
  #endif
+     return;
+ }
  
  VOID_HANDLER(AttlistDecl,