@@ -1572,6 +1572,7 @@ PHP_METHOD(DOMDocument, saveXML)
1572
1572
libxml_doc_props const * doc_props = dom_get_doc_props_read_only (intern -> document );
1573
1573
format = doc_props -> formatoutput ;
1574
1574
1575
+ int status ;
1575
1576
if (nodep != NULL ) {
1576
1577
/* Dump contents of Node */
1577
1578
DOM_GET_OBJ (node , nodep , xmlNodePtr , nodeobj );
@@ -1588,8 +1589,6 @@ PHP_METHOD(DOMDocument, saveXML)
1588
1589
/* Save libxml2 global, override its vaule, and restore after saving. */
1589
1590
old_xml_save_no_empty_tags = xmlSaveNoEmptyTags ;
1590
1591
xmlSaveNoEmptyTags = (options & LIBXML_SAVE_NOEMPTYTAG ) ? 1 : 0 ;
1591
- // TODO: return value?
1592
- int status ;
1593
1592
if (php_dom_follow_spec_intern (intern )) {
1594
1593
// TODO: dedup
1595
1594
xmlSaveCtxtPtr ctxt = xmlSaveToBuffer (buf , (const char * ) docp -> encoding , XML_SAVE_AS_XML );
@@ -1627,7 +1626,6 @@ PHP_METHOD(DOMDocument, saveXML)
1627
1626
php_error_docref (NULL , E_WARNING , "Could not create save context" );
1628
1627
RETURN_FALSE ;
1629
1628
}
1630
- int status ;
1631
1629
if (php_dom_follow_spec_intern (intern )) {
1632
1630
xmlOutputBufferPtr out = xmlOutputBufferCreateBuffer (buf , NULL ); // TODO: set handler instead of NULL, & check return value
1633
1631
status = dom_xml_serialize (ctxt , out , (xmlNodePtr ) docp , format );
@@ -1636,13 +1634,12 @@ PHP_METHOD(DOMDocument, saveXML)
1636
1634
} else {
1637
1635
status = xmlSaveDoc (ctxt , docp );
1638
1636
}
1639
- if (UNEXPECTED (status < 0 )) {
1640
- (void ) xmlSaveClose (ctxt );
1641
- xmlBufferFree (buf );
1642
- php_error_docref (NULL , E_WARNING , "Could not save document" );
1643
- RETURN_FALSE ;
1644
- }
1645
- xmlSaveClose (ctxt );
1637
+ (void ) xmlSaveClose (ctxt );
1638
+ }
1639
+ if (UNEXPECTED (status < 0 )) {
1640
+ xmlBufferFree (buf );
1641
+ php_error_docref (NULL , E_WARNING , "Could not save document" );
1642
+ RETURN_FALSE ;
1646
1643
}
1647
1644
mem = xmlBufferContent (buf );
1648
1645
if (!mem ) {
0 commit comments