@@ -1041,21 +1041,33 @@ PHP_METHOD(DOMDocument, getElementById)
1041
1041
}
1042
1042
/* }}} end dom_document_get_element_by_id */
1043
1043
1044
- static void php_dom_transfer_document_ref (xmlNodePtr node , dom_object * dom_object_document , xmlDocPtr document )
1044
+ static zend_always_inline void php_dom_transfer_document_ref_single_node (xmlNodePtr node , php_libxml_ref_obj * new_document )
1045
+ {
1046
+ php_libxml_node_ptr * iteration_object_ptr = node -> _private ;
1047
+ if (iteration_object_ptr ) {
1048
+ php_libxml_node_object * iteration_object = iteration_object_ptr -> _private ;
1049
+ ZEND_ASSERT (iteration_object != NULL );
1050
+ /* Must increase refcount first because we could be the last reference holder, and the document may be equal. */
1051
+ new_document -> refcount ++ ;
1052
+ php_libxml_decrement_doc_ref (iteration_object );
1053
+ iteration_object -> document = new_document ;
1054
+ }
1055
+ }
1056
+
1057
+ static void php_dom_transfer_document_ref (xmlNodePtr node , php_libxml_ref_obj * new_document )
1045
1058
{
1046
1059
if (node -> children ) {
1047
- php_dom_transfer_document_ref (node -> children , dom_object_document , document );
1060
+ php_dom_transfer_document_ref (node -> children , new_document );
1048
1061
}
1062
+
1049
1063
while (node ) {
1050
- php_libxml_node_ptr * iteration_object_ptr = node -> _private ;
1051
- if (iteration_object_ptr ) {
1052
- php_libxml_node_object * iteration_object = iteration_object_ptr -> _private ;
1053
- ZEND_ASSERT (iteration_object != NULL );
1054
- /* Must increase refcount first because we could be the last reference holder, and the document may be equal. */
1055
- dom_object_document -> document -> refcount ++ ;
1056
- php_libxml_decrement_doc_ref (iteration_object );
1057
- iteration_object -> document = dom_object_document -> document ;
1064
+ if (node -> type == XML_ELEMENT_NODE ) {
1065
+ for (xmlAttrPtr attr = node -> properties ; attr != NULL ; attr = attr -> next ) {
1066
+ php_dom_transfer_document_ref_single_node ((xmlNodePtr ) attr , new_document );
1067
+ }
1058
1068
}
1069
+
1070
+ php_dom_transfer_document_ref_single_node (node , new_document );
1059
1071
node = node -> next ;
1060
1072
}
1061
1073
}
@@ -1073,7 +1085,7 @@ bool php_dom_adopt_node(xmlNodePtr nodep, dom_object *dom_object_new_document, x
1073
1085
return false;
1074
1086
}
1075
1087
1076
- php_dom_transfer_document_ref (nodep , dom_object_new_document , new_document );
1088
+ php_dom_transfer_document_ref (nodep , dom_object_new_document -> document );
1077
1089
} else {
1078
1090
xmlUnlinkNode (nodep );
1079
1091
}
0 commit comments