[librsvg/librsvg-2.40] rsvg_free_xml_parser_and_doc(): New function; we'll use it instead of freeing things by hand



commit a4e69643dc9c28ff1cec91231658500fbc897841
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 8 10:23:04 2017 -0500

    rsvg_free_xml_parser_and_doc(): New function; we'll use it instead of freeing things by hand
    
    libxml2's xmlFreeParserCtxt(c) does not free the underlying c->myDoc;
    that needs to be freed separately.  We are forgetting to do that in a
    couple of places, so rsvg_free_xml_parser_and_doc() will take care of
    that in a single place.
    
    http://xmlsoft.org/html/libxml-parser.html#xmlFreeParserCtxt

 rsvg-base.c    |   20 ++++++++++++++++++++
 rsvg-private.h |    3 +++
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 21d328c..e2ae869 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2443,3 +2443,23 @@ _rsvg_handle_acquire_stream (RsvgHandle *handle,
     g_free (uri);
     return stream;
 }
+
+/* Frees the ctxt and its ctxt->myDoc - libxml2 doesn't free them together
+ * http://xmlsoft.org/html/libxml-parser.html#xmlFreeParserCtxt
+ *
+ * Returns NULL.
+ */
+xmlParserCtxtPtr
+rsvg_free_xml_parser_and_doc (xmlParserCtxtPtr ctxt)
+{
+    if (ctxt) {
+        if (ctxt->myDoc) {
+            xmlFreeDoc (ctxt->myDoc);
+            ctxt->myDoc = NULL;
+        }
+
+        xmlFreeParserCtxt (ctxt);
+    }
+
+    return NULL;
+}
diff --git a/rsvg-private.h b/rsvg-private.h
index 169d4bf..1433247 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -421,6 +421,9 @@ GInputStream *_rsvg_handle_acquire_stream (RsvgHandle *handle,
                                            char **content_type,
                                            GError **error);
 
+G_GNUC_INTERNAL
+xmlParserCtxtPtr rsvg_free_xml_parser_and_doc (xmlParserCtxtPtr ctxt) G_GNUC_WARN_UNUSED_RESULT;
+
 
 #define rsvg_return_if_fail(expr, error)    G_STMT_START{                      \
      if G_LIKELY(expr) { } else                                     \


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