From 0414fff205bad752573a4b2176d9f08afd096196 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 17 Aug 2018 16:22:35 +0200 Subject: [PATCH] Fix memory leak --- ext/dom/document.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/dom/document.c b/ext/dom/document.c index aba43f1385..9f9ce5e2f8 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -2175,11 +2175,16 @@ PHP_FUNCTION(dom_document_save_html) } buf = xmlBufferCreate(); - outBuf = xmlOutputBufferCreateBuffer(buf, NULL); - if (!outBuf || !buf) { + if (!buf) { php_error_docref(NULL, E_WARNING, "Could not fetch buffer"); RETURN_FALSE; } + outBuf = xmlOutputBufferCreateBuffer(buf, NULL); + if (!outBuf) { + xmlBufferFree(buf); + php_error_docref(NULL, E_WARNING, "Could not fetch output buffer"); + RETURN_FALSE; + } if (node->type == XML_DOCUMENT_FRAG_NODE) { for (node = node->children; node; node = node->next) { @@ -2205,6 +2210,7 @@ PHP_FUNCTION(dom_document_save_html) RETVAL_FALSE; } xmlOutputBufferClose(outBuf); + xmlBufferFree(buf); } else { int size = 0; #if LIBXML_VERSION >= 20623 -- 2.40.0