Skip to content

Commit c6ab4f6

Browse files
committed
Propagate save error
1 parent 1c026fc commit c6ab4f6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ext/dom/document.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ PHP_METHOD(DOMDocument, saveXML)
15721572
libxml_doc_props const* doc_props = dom_get_doc_props_read_only(intern->document);
15731573
format = doc_props->formatoutput;
15741574

1575+
int status;
15751576
if (nodep != NULL) {
15761577
/* Dump contents of Node */
15771578
DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
@@ -1588,8 +1589,6 @@ PHP_METHOD(DOMDocument, saveXML)
15881589
/* Save libxml2 global, override its vaule, and restore after saving. */
15891590
old_xml_save_no_empty_tags = xmlSaveNoEmptyTags;
15901591
xmlSaveNoEmptyTags = (options & LIBXML_SAVE_NOEMPTYTAG) ? 1 : 0;
1591-
// TODO: return value?
1592-
int status;
15931592
if (php_dom_follow_spec_intern(intern)) {
15941593
// TODO: dedup
15951594
xmlSaveCtxtPtr ctxt = xmlSaveToBuffer(buf, (const char *) docp->encoding, XML_SAVE_AS_XML);
@@ -1627,7 +1626,6 @@ PHP_METHOD(DOMDocument, saveXML)
16271626
php_error_docref(NULL, E_WARNING, "Could not create save context");
16281627
RETURN_FALSE;
16291628
}
1630-
int status;
16311629
if (php_dom_follow_spec_intern(intern)) {
16321630
xmlOutputBufferPtr out = xmlOutputBufferCreateBuffer(buf, NULL); // TODO: set handler instead of NULL, & check return value
16331631
status = dom_xml_serialize(ctxt, out, (xmlNodePtr) docp, format);
@@ -1636,13 +1634,12 @@ PHP_METHOD(DOMDocument, saveXML)
16361634
} else {
16371635
status = xmlSaveDoc(ctxt, docp);
16381636
}
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;
16461643
}
16471644
mem = xmlBufferContent(buf);
16481645
if (!mem) {

0 commit comments

Comments
 (0)