[libvirt] [libvirt PATCH v6 05/15] xen_xl: Adapt xenParseXLOS due to changes in xenConfigGetString

Fabiano Fidêncio fidencio at redhat.com
Tue Sep 18 18:48:08 UTC 2018


xenConfigGetString returns a newly-allocated pointer and it has to be
freed by the caller.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 src/xenconfig/xen_xl.c | 45 ++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index e4ef061cdb..cb1cab8482 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -108,26 +108,28 @@ static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
 static int
 xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
 {
+    int ret = -1;
     size_t i;
+    const char *bios = NULL;
+    const char *boot = NULL;
+
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
-        const char *bios;
-        const char *boot;
         int val = 0;
 
         if (xenConfigGetString(conf, "bios", &bios, NULL) < 0)
-            return -1;
+            goto cleanup;
 
         if (bios && STREQ(bios, "ovmf")) {
             if (VIR_ALLOC(def->os.loader) < 0)
-                return -1;
+                goto cleanup;
 
             def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
             def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
 
             if (VIR_STRDUP(def->os.loader->path,
                            LIBXL_FIRMWARE_DIR "/ovmf.bin") < 0)
-                return -1;
+                goto cleanup;
         } else {
             for (i = 0; i < caps->nguests; i++) {
                 if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM &&
@@ -135,24 +137,24 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
                     if (VIR_ALLOC(def->os.loader) < 0 ||
                         VIR_STRDUP(def->os.loader->path,
                                    caps->guests[i]->arch.defaultInfo.loader) < 0)
-                        return -1;
+                        goto cleanup;
                 }
             }
         }
 
 #ifdef LIBXL_HAVE_BUILDINFO_KERNEL
         if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
-            return -1;
+            goto cleanup;
 
         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
-            return -1;
+            goto cleanup;
 
         if (xenParseCmdline(conf, &def->os.cmdline) < 0)
-            return -1;
+            goto cleanup;
 #endif
 
         if (xenConfigGetString(conf, "boot", &boot, "c") < 0)
-            return -1;
+            goto cleanup;
 
         for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
             switch (boot[i]) {
@@ -174,7 +176,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
         }
 
         if (xenConfigGetBool(conf, "nestedhvm", &val, -1) < 0)
-            return -1;
+            goto cleanup;
 
         if (val != -1) {
             const char *vtfeature = "vmx";
@@ -189,7 +191,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
             if (!def->cpu) {
                 virCPUDefPtr cpu;
                 if (VIR_ALLOC(cpu) < 0)
-                    return -1;
+                    goto cleanup;
 
                 cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH;
                 cpu->type = VIR_CPU_TYPE_GUEST;
@@ -202,26 +204,31 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
                 if (virCPUDefAddFeature(def->cpu,
                                         vtfeature,
                                         VIR_CPU_FEATURE_DISABLE) < 0)
-                    return -1;
+                    goto cleanup;
             }
         }
     } else {
         if (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
-            return -1;
+            goto cleanup;
         if (xenConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
-            return -1;
+            goto cleanup;
 
         if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
-            return -1;
+            goto cleanup;
 
         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
-            return -1;
+            goto cleanup;
 
         if (xenParseCmdline(conf, &def->os.cmdline) < 0)
-            return -1;
+            goto cleanup;
     }
 
-    return 0;
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(bios);
+    VIR_FREE(boot);
+    return ret;
 }
 
 /*
-- 
2.17.1




More information about the libvir-list mailing list