summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/xsl/php_xsl.c11
-rw-r--r--ext/xsl/xsltprocessor.c25
2 files changed, 25 insertions, 11 deletions
diff --git a/ext/xsl/php_xsl.c b/ext/xsl/php_xsl.c
index 30db612f94..3b18a7946a 100644
--- a/ext/xsl/php_xsl.c
+++ b/ext/xsl/php_xsl.c
@@ -91,8 +91,15 @@ void xsl_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
if (((xsltStylesheetPtr) intern->ptr)->_private != NULL) {
((xsltStylesheetPtr) intern->ptr)->_private = NULL;
}
- /* libxslt uses _private for itself, so turning of the deregistering is maybe a solution
- we copied the doc at import, so it shouldn't be possible to be used from php land */
+ if (intern->document != NULL) {
+ if (--intern->document->refcount == 0) {
+ xmlFreeDoc((xmlDocPtr) intern->document->ptr);
+ efree(intern->document);
+ }
+ ((xsltStylesheetPtr) intern->ptr)->doc = NULL;
+ intern->document = NULL;
+ }
+
xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr);
intern->ptr = NULL;
}
diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c
index cfe4fa3dc3..ad1ad7f4ca 100644
--- a/ext/xsl/xsltprocessor.c
+++ b/ext/xsl/xsltprocessor.c
@@ -126,7 +126,6 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
zval *id, *docp = NULL;
xmlDoc *doc = NULL;
xsltStylesheetPtr sheetp, oldsheetp;
- xmlDocPtr newdocp;
xsl_object *intern;
node_object *docobj;
@@ -135,15 +134,12 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &docp) == FAILURE) {
RETURN_FALSE;
}
+
DOC_GET_OBJ(doc, docp, xmlDocPtr, docobj);
- /* copy the doc, so that it's not accessable from outside
- FIXME: and doubling memory consumption...
- */
- newdocp = xmlCopyDoc(doc, 1);
- sheetp = xsltParseStylesheetDoc(newdocp);
+
+ sheetp = xsltParseStylesheetDoc(doc);
if (!sheetp) {
- xmlFreeDoc(newdocp);
RETURN_FALSE;
}
@@ -154,10 +150,21 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
efree(((xsltStylesheetPtr) intern->ptr)->_private);
((xsltStylesheetPtr) intern->ptr)->_private = NULL;
}
- //FIXME: more non-thread safe stuff
+ if (intern->document != NULL) {
+ if (--intern->document->refcount == 0) {
+ xmlFreeDoc((xmlDocPtr) intern->document->ptr);
+ efree(intern->document);
+ }
+ ((xsltStylesheetPtr) intern->ptr)->doc = NULL;
+ intern->document = NULL;
+ }
xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr);
intern->ptr = NULL;
- }
+ }
+
+ intern->document = docobj->document;
+ intern->document->refcount++;
+
php_xsl_set_object(id, sheetp TSRMLS_CC);
}
/* }}} end xsl_xsltprocessor_import_stylesheet */