summaryrefslogtreecommitdiff
path: root/ext/domxml/php_domxml.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/domxml/php_domxml.c')
-rw-r--r--ext/domxml/php_domxml.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c
index 27e41b5d97..42e0856513 100644
--- a/ext/domxml/php_domxml.c
+++ b/ext/domxml/php_domxml.c
@@ -602,11 +602,10 @@ static inline void node_wrapper_dtor(xmlNodePtr node)
/* This function should only be used when freeing nodes
as dependant objects are destroyed */
-static inline void node_wrapper_free(xmlNodePtr node)
+static inline void node_wrapper_free(xmlNodePtr node TSRMLS_DC)
{
zval *wrapper, **handle;
int type, refcount = 0;
- TSRMLS_FETCH();
if (!node) {
return;
@@ -616,7 +615,6 @@ static inline void node_wrapper_free(xmlNodePtr node)
if (wrapper != NULL ) {
/* All references need to be destroyed */
if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == SUCCESS) {
- TSRMLS_FETCH();
if (zend_list_find(Z_LVAL_PP(handle), &type)) {
zend_list_delete(Z_LVAL_PP(handle));
}
@@ -644,10 +642,10 @@ static inline void attr_list_wrapper_dtor(xmlAttrPtr attr)
/* destroyref is a bool indicating if all registered objects for nodes
within the tree should be destroyed */
-static inline void node_list_wrapper_dtor(xmlNodePtr node, int destroyref)
+static inline void node_list_wrapper_dtor(xmlNodePtr node, int destroyref TSRMLS_DC)
{
while (node != NULL) {
- node_list_wrapper_dtor(node->children, destroyref);
+ node_list_wrapper_dtor(node->children, destroyref TSRMLS_CC);
switch (node->type) {
/* Skip property freeing for the following types */
case XML_ATTRIBUTE_DECL:
@@ -659,11 +657,11 @@ static inline void node_list_wrapper_dtor(xmlNodePtr node, int destroyref)
/* Attribute Nodes contain accessible children
Call this function with the propert list
attr_list_wrapper_dtor(node->properties); */
- node_list_wrapper_dtor((xmlNodePtr) node->properties, destroyref);
+ node_list_wrapper_dtor((xmlNodePtr) node->properties, destroyref TSRMLS_CC);
}
if (destroyref == 1) {
- node_wrapper_free(node);
+ node_wrapper_free(node TSRMLS_CC);
} else {
node_wrapper_dtor(node);
}
@@ -731,7 +729,7 @@ static void php_free_xml_doc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
xmlDoc *doc = (xmlDoc *) rsrc->ptr;
if (doc) {
- node_list_wrapper_dtor(doc->children, 0);
+ node_list_wrapper_dtor(doc->children, 0 TSRMLS_CC);
node_wrapper_dtor((xmlNodePtr) doc);
xmlFreeDoc(doc);
}
@@ -746,8 +744,8 @@ static void php_free_xml_node(zend_rsrc_list_entry *rsrc TSRMLS_DC)
if (node->parent == NULL) {
/* Attribute Nodes ccontain accessible children
attr_list_wrapper_dtor(node->properties); */
- node_list_wrapper_dtor((xmlNodePtr) node->properties, 0);
- node_list_wrapper_dtor(node->children, 0);
+ node_list_wrapper_dtor((xmlNodePtr) node->properties, 0 TSRMLS_CC);
+ node_list_wrapper_dtor(node->children, 0 TSRMLS_CC);
node_wrapper_dtor(node);
xmlFreeNode(node);
} else {
@@ -760,7 +758,7 @@ static void php_free_xml_attr(zend_rsrc_list_entry *rsrc TSRMLS_DC)
xmlNodePtr node = (xmlNodePtr) rsrc->ptr;
if (node->parent == NULL) {
/* Attribute Nodes contain accessible children */
- node_list_wrapper_dtor(node->children, 0);
+ node_list_wrapper_dtor(node->children, 0 TSRMLS_CC);
node_wrapper_dtor(node);
xmlFreeProp((xmlAttrPtr) node);
} else {
@@ -3862,11 +3860,14 @@ PHP_FUNCTION(domxml_doc_imported_node)
DOMXML_GET_OBJ(srcnode, arg1, le_domxmlnodep);
- node = xmlCopyNode(srcnode, recursive);
+ /* node = xmlCopyNode(srcnode, recursive); */
+ node = xmlDocCopyNode(srcnode, docp, recursive);
if (!node) {
RETURN_FALSE;
}
- node->doc = docp; /* Not enough because other nodes in the tree are not set */
+ /* No longer need handled by xmlDocCopyNode
+ node->doc = docp;
+ */
DOMXML_RET_OBJ(rv, node, &ret);
}
@@ -4358,7 +4359,7 @@ PHP_FUNCTION(domxml_doc_add_root)
{
zval *id, *rv = NULL;
xmlDoc *docp;
- xmlNode *nodep;
+ xmlNode *nodep, *root;
int ret, name_len;
char *name;
@@ -4369,7 +4370,14 @@ PHP_FUNCTION(domxml_doc_add_root)
RETURN_FALSE;
}
- xmlDocSetRootElement(docp, nodep);
+ if ((root = xmlDocSetRootElement(docp, nodep)) != NULL) {
+ /* Root node already unlinked from xmlDocSetRootElement */
+ if (dom_object_get_data(root) == NULL) {
+ node_list_unlink(root->children);
+ node_list_unlink((xmlNodePtr) root->properties);
+ xmlFreeNode(root);
+ }
+ }
DOMXML_RET_OBJ(rv, nodep, &ret);
}
@@ -4473,11 +4481,11 @@ PHP_FUNCTION(domxml_doc_free_doc)
RETURN_FALSE;
}
- node_list_wrapper_dtor(docp->children, 1);
- node_list_wrapper_dtor((xmlNodePtr) docp->properties, 1);
+ node_list_wrapper_dtor(docp->children, 1 TSRMLS_CC);
+ node_list_wrapper_dtor((xmlNodePtr) docp->properties, 1 TSRMLS_CC);
/* Attribute Nodes ccontain accessible children
attr_list_wrapper_dtor(docp->properties); */
- node_wrapper_free(docp);
+ node_wrapper_free(docp TSRMLS_CC);
RETURN_TRUE;
}
@@ -5342,6 +5350,7 @@ PHP_FUNCTION(domxml_xslt_stylesheet)
sheetp = xsltParseStylesheetDoc(docp);
if (!sheetp) {
+ xmlFreeDoc(docp);
RETURN_FALSE;
}
@@ -5375,6 +5384,7 @@ PHP_FUNCTION(domxml_xslt_stylesheet_doc)
sheetp = xsltParseStylesheetDoc(newdocp);
if (!sheetp) {
+ xmlFreeDoc(newdocp);
RETURN_FALSE;
}