summaryrefslogtreecommitdiff
path: root/Modules/pyexpat.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2003-02-02 03:54:17 +0000
committerFred Drake <fdrake@acm.org>2003-02-02 03:54:17 +0000
commit6ac2c56b2368c8fad9c0133a9c9d6b617adff03f (patch)
treedcee1e352d64eb3ae44c858e6573e612307f248c /Modules/pyexpat.c
parentb9e0f25e8e89fef6032ab47c36ec90f0f78c47aa (diff)
downloadcpython-6ac2c56b2368c8fad9c0133a9c9d6b617adff03f.tar.gz
Fix memory leak: free memory storing the content model passed to the
ElementDeclHandler by Expat. Fixes SF bug #676990.
Diffstat (limited to 'Modules/pyexpat.c')
-rw-r--r--Modules/pyexpat.c72
1 files changed, 48 insertions, 24 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 436f891adf..0f6608a6f9 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -683,35 +683,59 @@ conv_content_model(XML_Content * const model,
return result;
}
-static PyObject *
-conv_content_model_utf8(XML_Content * const model)
+static void
+my_ElementDeclHandler(void *userData,
+ const XML_Char *name,
+ XML_Content *model)
{
- return conv_content_model(model, conv_string_to_utf8);
-}
+ xmlparseobject *self = (xmlparseobject *)userData;
+ PyObject *args = NULL;
-#ifdef Py_USING_UNICODE
-static PyObject *
-conv_content_model_unicode(XML_Content * const model)
-{
- return conv_content_model(model, conv_string_to_unicode);
-}
+ if (have_handler(self, ElementDecl)) {
+ PyObject *rv = NULL;
+ PyObject *modelobj, *nameobj;
-VOID_HANDLER(ElementDecl,
- (void *userData,
- const XML_Char *name,
- XML_Content *model),
- ("NO&",
- string_intern(self, name),
- (self->returns_unicode ? conv_content_model_unicode
- : conv_content_model_utf8),model))
+ if (flush_character_buffer(self) < 0)
+ goto finally;
+#ifdef Py_USING_UNICODE
+ modelobj = conv_content_model(model,
+ (self->returns_unicode
+ ? conv_string_to_unicode
+ : conv_string_to_utf8));
#else
-VOID_HANDLER(ElementDecl,
- (void *userData,
- const XML_Char *name,
- XML_Content *model),
- ("NO&",
- string_intern(self, name), conv_content_model_utf8,model))
+ modelobj = conv_content_model(model, conv_string_to_utf8);
#endif
+ if (modelobj == NULL) {
+ flag_error(self);
+ goto finally;
+ }
+ nameobj = string_intern(self, name);
+ if (nameobj == NULL) {
+ Py_DECREF(modelobj);
+ flag_error(self);
+ goto finally;
+ }
+ args = Py_BuildValue("NN", string_intern(self, name), 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(self->itself, model);
+ return;
+}
VOID_HANDLER(AttlistDecl,
(void *userData,