Re: [xml] xmlInitParser: Necessary or not?



On Fri, Oct 05, 2007 at 08:12:39PM +0200, Ralf Junker wrote:
Hello,

I understand that xmlCleanupParser should be called to clean up after libxml and free allocated global 
memory. However, xmlCleanupParser only works if the parser has been previously initialized. The only way to 
do so is to call xmlInitParser (see source for details).

Now I find that many functions call xmlInitParser automatically (htmlNodeDump, htmlReadMemory, to name but 
a few) and make xmlCleanupParser work. On the other hand, many functions allocate global variables and do 
not call xmlInitParser. As a result, xmlCleanupParser will not work. So if an app uses those functions only 
and does not call xmlInitParser separately, its call to xmlCleanupParser will have no effect and the 
application will leak memory.

Questions:

* Is it always recommended or even necessary to call xmlInitParser regardless of which functions are used?

  Not needed if you just do a simple parsing as the parsing entry points
are the one with a guard. But call it if you do anything more complex
than 'I just need to parse a file'

* The documentation suggests to call xmlInitParser "once before processing in case of use in multithreaded 
programs." As demonstrated above, it might be necessary to call it even in single-threaded programs. Is 
this not a documentation error?

  I don't think so. The examples call it, actually the examples do something
even better: use LIBXML_TEST_VERSION which does the checking against the
shared lib to make sure there is no versionning problem. And that in 
turn calls xmlInitParser() . 

* xmlInitParser and xmlCleanupParser cover libxml. Do I need to take care of additional initialization and 
finalization besides these two in libxml?

  not that I can think of

* Can I expect similar problems in libxslt, too? Which init/finalize functions should I call for libxslt?

  If you don't plug XSLT extensions (yours or though exsltRegisterAll())
no, except for the security preference functions. See xsltproc.c in the
tarball.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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