Skip to content

Commit 0414fff

Browse files
committed
Fix memory leak
1 parent aa7777d commit 0414fff

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ext/dom/document.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,11 +2175,16 @@ PHP_FUNCTION(dom_document_save_html)
21752175
}
21762176

21772177
buf = xmlBufferCreate();
2178-
outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
2179-
if (!outBuf || !buf) {
2178+
if (!buf) {
21802179
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
21812180
RETURN_FALSE;
21822181
}
2182+
outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
2183+
if (!outBuf) {
2184+
xmlBufferFree(buf);
2185+
php_error_docref(NULL, E_WARNING, "Could not fetch output buffer");
2186+
RETURN_FALSE;
2187+
}
21832188

21842189
if (node->type == XML_DOCUMENT_FRAG_NODE) {
21852190
for (node = node->children; node; node = node->next) {
@@ -2205,6 +2210,7 @@ PHP_FUNCTION(dom_document_save_html)
22052210
RETVAL_FALSE;
22062211
}
22072212
xmlOutputBufferClose(outBuf);
2213+
xmlBufferFree(buf);
22082214
} else {
22092215
int size = 0;
22102216
#if LIBXML_VERSION >= 20623

0 commit comments

Comments
 (0)