[virt-tools-list] [libosinfo 1/4] loader: Use xmlFree to free libxml2 strings

Christophe Fergeau cfergeau at redhat.com
Thu Dec 6 09:53:57 UTC 2012


As libxml2 and glib memory allocation functions can be overridden
with custom functions, it's important to use the right free functions
for allocated memory.
---
 osinfo/osinfo_loader.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index a4dd01d..1c27187 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -355,7 +355,7 @@ static void osinfo_loader_device(OsinfoLoader *loader,
     }
 
     OsinfoDevice *device = osinfo_loader_get_device(loader, id);
-    g_free(id);
+    xmlFree(id);
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(device), keys, ctxt, root, err);
 }
@@ -384,7 +384,7 @@ static void osinfo_loader_device_link(OsinfoLoader *loader,
             goto cleanup;
         }
         OsinfoDevice *dev = osinfo_loader_get_device(loader, id);
-        g_free(id);
+        xmlFree(id);
 
         OsinfoDeviceLink *devlink = NULL;
         if (OSINFO_IS_PLATFORM(entity)) {
@@ -432,7 +432,7 @@ static void osinfo_loader_product_relshp(OsinfoLoader *loader,
             relproduct = OSINFO_PRODUCT(osinfo_loader_get_platform(loader, id));
         else
             relproduct = OSINFO_PRODUCT(osinfo_loader_get_os(loader, id));
-        g_free(id);
+        xmlFree(id);
 
         osinfo_product_add_related(product, relshp, relproduct);
     }
@@ -504,7 +504,7 @@ static void osinfo_loader_platform(OsinfoLoader *loader,
     }
 
     OsinfoPlatform *platform = osinfo_loader_get_platform(loader, id);
-    g_free(id);
+    xmlFree(id);
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(platform), keys, ctxt, root, err);
     if (error_is_set(err))
@@ -537,7 +537,7 @@ static void osinfo_loader_deployment(OsinfoLoader *loader,
     gchar *osid = osinfo_loader_string("string(./os/@id)", ctxt, err);
     if (!osid && 0) {
         OSINFO_ERROR(err, _("Missing deployment os id property"));
-        g_free(id);
+        xmlFree(id);
         return;
     }
     OsinfoOs *os = osinfo_loader_get_os(loader, osid);
@@ -546,14 +546,14 @@ static void osinfo_loader_deployment(OsinfoLoader *loader,
     gchar *platformid = osinfo_loader_string("string(./platform/@id)", ctxt, err);
     if (!platformid) {
         OSINFO_ERROR(err, _("Missing deployment platform id property"));
-        g_free(id);
+        xmlFree(id);
         return;
     }
     OsinfoPlatform *platform = osinfo_loader_get_platform(loader, platformid);
     g_free(platformid);
 
     OsinfoDeployment *deployment = osinfo_deployment_new(id, os, platform);
-    g_free(id);
+    xmlFree(id);
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(deployment), keys, ctxt, root, err);
     if (error_is_set(err))
@@ -590,8 +590,8 @@ static void osinfo_loader_install_config_params(OsinfoLoader *loader,
         osinfo_install_script_add_config_param(OSINFO_INSTALL_SCRIPT(entity),
                                                param);
 
-        g_free(name);
-        g_free(policy);
+        xmlFree(name);
+        xmlFree(policy);
     };
 
     g_free(nodes);
@@ -647,7 +647,7 @@ static void osinfo_loader_install_script(OsinfoLoader *loader,
 
     OsinfoInstallScript *installScript = osinfo_loader_get_install_script(loader,
                                                                           id);
-    g_free(id);
+    xmlFree(id);
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(installScript), keys, ctxt, root, err);
     if (error_is_set(err))
@@ -1016,7 +1016,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
         }
         OsinfoInstallScript *script;
         script = osinfo_loader_get_install_script(loader, scriptid);
-        g_free(scriptid);
+        xmlFree(scriptid);
 
         osinfo_os_add_install_script(os, script);
     }
@@ -1024,7 +1024,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
     g_free(nodes);
 
 cleanup:
-    g_free(id);
+    xmlFree(id);
 }
 
 static void osinfo_loader_root(OsinfoLoader *loader,
-- 
1.8.0.1




More information about the virt-tools-list mailing list