[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[xml] [PATCH] Python xpathEval method can leak



The python xpathEval convenience method on xmlCore leaks an
xmlXPathContext if the expression is invalid or otherwise fails. Fix
attached, with test that can probably be adapted to go in the tests
dir.

I'd like to do a real fix for the xpathEval2 thing just below, but
it'd mean bindings changes, so then might as well rewrite cleaner...
spirals into a big job.

Martin

Attachment: simple_leak.patch
Description: Binary data

import libxml2

libxml2.debugMemory(True)

d = libxml2.parseDoc("<fish/>")
for expr in ("/fish[.=$var]", "local-name('one','two')", "~?)%^*("):
    try:
        result = d.xpathEval(expr)
    except libxml2.xpathError, e:
        print "xpathError raised:", e
    else:
        raise ValueError("Unexpected success", expr, result)
d.freeDoc()

libxml2.cleanupParser()
leakedbytes = libxml2.debugMemory(True)
if leakedbytes == 0:
    print "OK"
else:
    print "Memory leak", leakedbytes, "bytes"
    # drop file to .memdump file in cwd, but won't work if not compiled in
    libxml2.dumpMemory()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]