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



commit 27449ad35391e7b03a29c1579a751a682222bcb1
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 deb2d54..ea3f9ea 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2653,3 +2653,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 e9e628b..bf0d737 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -561,6 +561,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]