[libxml2] Fix memory leak in xmlSwitchInputEncodingInt error path



commit 3776cb4745cecd8f477b45857c9033a908f25cf3
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Thu Nov 22 15:27:28 2018 +0100

    Fix memory leak in xmlSwitchInputEncodingInt error path
    
    Found by OSS-Fuzz.

 parserInternals.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/parserInternals.c b/parserInternals.c
index 09876ab4..0f015ded 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -1240,8 +1240,18 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
         * size to be able to convert the buffer.
         */
        xmlErrInternal(ctxt, "switching encoding : no input\n", NULL);
+        /*
+         * Callers assume that the input buffer takes ownership of the
+         * encoding handler. xmlCharEncCloseFunc frees unregistered
+         * handlers and avoids a memory leak.
+         */
+        xmlCharEncCloseFunc(handler);
        return (-1);
     }
+    /*
+     * We should actually raise an error here, see issue #34.
+     */
+    xmlCharEncCloseFunc(handler);
     return (0);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]