[netcf-devel] [PATCH] Fix initialization of libxslt

Daniel Veillard veillard at redhat.com
Fri Aug 14 07:48:33 UTC 2009


On Thu, Aug 13, 2009 at 06:12:38PM -0700, David Lutterkort wrote:
> We used to initialize libxslt (and register extension modules) every time
> ncf_init was called, and deregister/free libxslt globals every time
> ncf_close was called. That breaks when libnetcf is used together with other
> libraries that use libxslt, since they might continue using it after a call
> to ncf_close.
> 
> To work around this, we now initialize and register our extension modules
> only once, essentially statically, and just live with the small leak that
> not unregistering and cleaning up globals causes.
> 
> Bug report and suggested fix from Daniel Veillard (<veillard at redhat.com>)

  Yes, thanks, the patch does what I think is needed to avoid threading
problems with libxslt in netcf, unfortunately the modules registered
globally can't be unplugged in ncf_close as other threads may still use
netcf and need those, same for the global variables of libxslt.
  My suggestion is that applications using netcf should call

  - xslt_ext_unregister(); <- or another public cleanup function
                              to be called when libnetcf is not used
                              anymore in the application
  - xsltCleanupGlobals();
  - xmlCleanupParser();

when they are about to exit, this will allow to have clean runs when
using valgrind --leak-check or other leak checking tools on the
application. The amount of memory left used is rather minimal, most of
the data like the stylesheet are still cleaned up on ncf_close()
the amount maintained by the libraries should be in the order of
a few kilobytes, neglectible by current standards.

[...]
> +static void drv_init_once(void) {
> +    // FIXME: How do we report errors ?
> +    xsltInit();
> +    xslt_ext_register();
> +}
> +

  Unfortunately pthread_once() has really no mechanism for passing
initialization errors back to the application :-\

 Patch looks good to me !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


More information about the netcf-devel mailing list