]> granicus.if.org Git - php/commitdiff
Fix memory leak
authorAnatol Belski <ab@php.net>
Fri, 17 Aug 2018 14:22:35 +0000 (16:22 +0200)
committerAnatol Belski <ab@php.net>
Fri, 17 Aug 2018 14:22:35 +0000 (16:22 +0200)
ext/dom/document.c

index aba43f13858f162f7f08851d0f3e8ebb2f07a665..9f9ce5e2f8fb5b2f59a30ea5a40f0ccd27425ae9 100644 (file)
@@ -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