I'm not sure where the problem is, but this code leaks a reference:
   parser = ET.XMLParser() ; parser.feed('<x>text</x>')

You need this to set it up:
  from xmlcore.etree import cElementTree as ET

This isn't a memory leak according to valgrind.

Also, I noticed several places where errors where being ignored.  What
is the procedure for the element tree?  Are we supposed to modify it
in the python SVN or treat it as read-only?

The patch below fixes a few small problems.  There were some others I
noticed, but didn't add to the patch.

n
--
Index: Modules/_elementtree.c
===================================================================
--- Modules/_elementtree.c      (revision 41747)
+++ Modules/_elementtree.c      (working copy)
@@ -905,6 +905,9 @@
     }

     args = PyTuple_New(2);
+    if (!args)
+       return NULL;
+
     Py_INCREF(self); PyTuple_SET_ITEM(args, 0, (PyObject*) self);
     Py_INCREF(tag);  PyTuple_SET_ITEM(args, 1, (PyObject*) tag);

@@ -1641,8 +1644,8 @@
         PyObject* node = (PyObject*) self->last;
         res = PyTuple_New(2);
         if (res) {
-            Py_INCREF(action); PyTuple_SET_ITEM(res, 0, (PyObject*) action);
-            Py_INCREF(node);   PyTuple_SET_ITEM(res, 1, (PyObject*) node);
+            Py_INCREF(action); PyTuple_SET_ITEM(res, 0, action);
+            Py_INCREF(node);   PyTuple_SET_ITEM(res, 1, node);
             PyList_Append(self->events, res);
             Py_DECREF(res);
         } else
@@ -2586,10 +2589,14 @@
 #endif

     m = Py_InitModule("_elementtree", _functions);
+    if (!m)
+       return;

     /* python glue code */

     g = PyDict_New();
+    if (!g)
+       return;

     PyDict_SetItemString(g, "__builtins__", PyEval_GetBuiltins());
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to