[Libosinfo] [PATCH 14/14] install-script: Return glib-allocated string from ::apply_xslt()

Christophe Fergeau cfergeau at redhat.com
Wed Jun 8 10:01:18 UTC 2016


Strings created by libxml2 should be freed with xmlFree while glib ones
should be freed with g_free, so it's cleaner to allocate the string
returned from ::apply_xslt() with the glib allocator as it's meant to be
g_free'ed later on.
---
 osinfo/osinfo_install_script.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index ebe1887..9206101 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -808,6 +808,7 @@ static gchar *osinfo_install_script_apply_xslt(xsltStylesheetPtr ss,
                                                GError **error)
 {
     xsltTransformContextPtr ctxt;
+    xmlChar *xsltResult;
     gchar *ret = NULL;
     xmlDocPtr docOut = NULL;
     int len;
@@ -822,10 +823,12 @@ static gchar *osinfo_install_script_apply_xslt(xsltStylesheetPtr ss,
         goto cleanup;
     }
 
-    if (xsltSaveResultToString((xmlChar **)&ret, &len, docOut, ss) < 0) {
+    if (xsltSaveResultToString(&xsltResult, &len, docOut, ss) < 0) {
         g_set_error(error, 0, 0, "%s", _("Unable to convert XSL output to string"));
         goto cleanup;
     }
+    ret = g_strdup((gchar *)xsltResult);
+    xmlFree(xsltResult);
 
  cleanup:
     xmlFreeDoc(docOut);
-- 
2.7.4




More information about the Libosinfo mailing list