[xslt] small patch for xsltFreeStylePreComps()



Hello, All!

I run into a small problem with re-using XSLT stylesheet document
in the following scenario (the same xmlDocPtr is used for more
than one stylesheet):

	xmlDocPtr xslt_doc;
	xsltStylesheetPtr stylesheet;

	xslt_doc = ... ; /* Get xslt doc somehow */
	...

	/* use doc stylesheet first time */
	stylesheet = xsltParseStylesheetDoc(xslt_doc);
	out1 = xsltApplyStylesheet(stylesheet, in1);
	... /* consume out1 */
	xsltFreeStylesheet(stylesheet);
	
	...

	/* use doc stylesheet first time */
	stylesheet = xsltParseStylesheetDoc(xslt_doc);
	out2 = xsltApplyStylesheet(stylesheet, in2);   <--- crash
	... /* consume out2 */
	xsltFreeStylesheet(stylesheet);


I understand that this is probably a corner case scenario since it is much better to do not re-create xsltStylesheetPtr second time. But at the moment it is not possible to do in my case.

It turns out that the crash is caused by invalid pointer in
"psvi" member of xmlNodePtr. The actual data structure was freed
by the first xsltFreeStylesheet() call but the "psvi" pointer
was still pointed to it. The attached patch fixes the problem by
making sure that we cleanup this "psvi" pointer when we destroy
the data structure.

I would appreciate if someone can take a look at the patch and
check that it is not doing something stupid :)

Thanks,
Aleksey Sanin
diff -ur libxslt/preproc.c libxslt/preproc.c
--- libxslt/preproc.c	2005-03-29 05:12:59.000000000 -0800
+++ libxslt/preproc.c	2006-05-02 19:09:33.682620800 -0700
@@ -1321,6 +1321,8 @@
     cur = style->preComps;
     while (cur != NULL) {
 	next = cur->next;
+       if(cur->inst != NULL)
+           cur->inst->psvi = NULL;
 	if (cur->type == XSLT_FUNC_EXTENSION)
 	    cur->free(cur);
 	else


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