[PATCH] build: detect potentential uninitialized variables

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

 



Even with -Wuninitialized (which is part of autobuild.sh
--enable-compile-warnings=error), gcc does NOT catch this
use of an uninitialized variable:

{
  if (cond)
    goto error;
  int a = 1;
error:
  printf("%d", a);
}

which prints 0 (if the stack was previously wiped) if cond
was true.  Clang will catch it, but we dont' use clang as
often.  Using gcc -Wjump-misses-init gives false positives:

{
  if (cond)
    goto error;
  int a = 1;
  return a;
error:
  return 0;
}

Here, a was never used in the scope of the error block, so
declaring it after goto is technically fine (and clang agrees);
however, given that our HACKING already documents a preference
to C89 decl-before-statement, the false positive warning is
enough of a prod to comply with HACKING.

[Personally, I'd _really_ rather use C99 decl-after-statement
to minimize scope, but until gcc can efficiently and reliably
catch scoping and uninitialized usage bugs, I'll settle with
the compromise of enforcing a coding standard that rejects
false positives.]

* acinclude.m4 (LIBVIRT_COMPILE_WARNINGS): Add -Wjump-misses-init.
* src/util/util.c (__virExec): Adjust offenders.
* src/conf/domain_conf.c (virDomainTimerDefParseXML): Likewise.
* src/remote/remote_driver.c (doRemoteOpen): Likewise.
* src/phyp/phyp_driver.c (phypGetLparNAME, phypGetLparProfile)
(phypGetVIOSFreeSCSIAdapter, phypVolumeGetKey)
(phypGetStoragePoolDevice)
(phypVolumeGetPhysicalVolumeByStoragePool)
(phypVolumeGetPath): Likewise.
* src/vbox/vbox_tmpl.c (vboxNetworkUndefineDestroy)
(vboxNetworkCreate, vboxNetworkDumpXML)
(vboxNetworkDefineCreateXML): Likewise.
* src/xenapi/xenapi_driver.c (getCapsObject)
(xenapiDomainDumpXML): Likewise.
* src/xenapi/xenapi_utils.c (createVMRecordFromXml): Likewise.
* src/security/security_selinux.c (SELinuxGenNewContext):
Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetPtyPaths):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainShutdown)
(qemudDomainBlockStats, qemudDomainMemoryPeek): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendCreateIfaceIQN): Likewise.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
---
 acinclude.m4                        |    1 +
 src/conf/domain_conf.c              |    6 ++++--
 src/node_device/node_device_udev.c  |    3 ++-
 src/phyp/phyp_driver.c              |   24 ++++++++++++++++--------
 src/qemu/qemu_command.c             |    6 ++++--
 src/qemu/qemu_driver.c              |    9 ++++++---
 src/qemu/qemu_hotplug.c             |    4 ++--
 src/qemu/qemu_monitor_text.c        |    2 +-
 src/qemu/qemu_process.c             |    3 ++-
 src/remote/remote_driver.c          |   12 +++++++-----
 src/security/security_selinux.c     |    3 ++-
 src/storage/storage_backend_iscsi.c |   25 ++++++++++++-------------
 src/util/util.c                     |    3 ++-
 src/vbox/vbox_tmpl.c                |   28 ++++++++++++++--------------
 src/xenapi/xenapi_driver.c          |   24 ++++++++++++++----------
 src/xenapi/xenapi_utils.c           |   10 ++++++----
 16 files changed, 95 insertions(+), 68 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 838ec46..22eb7af 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -49,6 +49,7 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
 	try_compiler_flags="$try_compiler_flags -Wredundant-decls"
 	try_compiler_flags="$try_compiler_flags -Wno-sign-compare"
 	try_compiler_flags="$try_compiler_flags -Wlogical-op"
+	try_compiler_flags="$try_compiler_flags -Wjump-misses-init"
 	try_compiler_flags="$try_compiler_flags $common_flags"
 	if test "$enable_compile_warnings" = "error" ; then
 	    try_compiler_flags="$try_compiler_flags -Werror"
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b6aaf33..90a1317 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3557,6 +3557,8 @@ virDomainTimerDefParseXML(const xmlNodePtr node,

     virDomainTimerDefPtr def;
     xmlNodePtr oldnode = ctxt->node;
+    xmlNodePtr catchup;
+    int ret;

     if (VIR_ALLOC(def) < 0) {
         virReportOOMError();
@@ -3610,7 +3612,7 @@ virDomainTimerDefParseXML(const xmlNodePtr node,
         }
     }

-    int ret = virXPathULong("string(./frequency)", ctxt, &def->frequency);
+    ret = virXPathULong("string(./frequency)", ctxt, &def->frequency);
     if (ret == -1) {
         def->frequency = 0;
     } else if (ret < 0) {
@@ -3629,7 +3631,7 @@ virDomainTimerDefParseXML(const xmlNodePtr node,
         }
     }

-    xmlNodePtr catchup = virXPathNode("./catchup", ctxt);
+    catchup = virXPathNode("./catchup", ctxt);
     if (catchup != NULL) {
         ret = virXPathULong("string(./catchup/@threshold)", ctxt,
                             &def->catchup.threshold);
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 44df16e..372f1d1 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -415,6 +415,7 @@ static int udevProcessPCI(struct udev_device *device,
     const char *syspath = NULL;
     union _virNodeDevCapData *data = &def->caps->data;
     int ret = -1;
+    char *p;

     syspath = udev_device_get_syspath(device);

@@ -425,7 +426,7 @@ static int udevProcessPCI(struct udev_device *device,
         goto out;
     }

-    char *p = strrchr(syspath, '/');
+    p = strrchr(syspath, '/');

     if ((p == NULL) || (udevStrToLong_ui(p+1,
                                          &p,
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 51f9ff6..b17d90b 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1337,6 +1337,7 @@ phypGetLparNAME(LIBSSH2_SESSION * session, const char *managed_system,
     char *ret = NULL;
     int exit_status = 0;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     virBufferAddLit(&buf, "lssyscfg -r lpar");
     if (system_type == HMC)
@@ -1354,7 +1355,7 @@ phypGetLparNAME(LIBSSH2_SESSION * session, const char *managed_system,
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -1675,6 +1676,7 @@ phypGetLparProfile(virConnectPtr conn, int lpar_id)
     char *cmd = NULL;
     char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     virBufferAddLit(&buf, "lssyscfg");
     if (system_type == HMC)
@@ -1694,7 +1696,7 @@ phypGetLparProfile(virConnectPtr conn, int lpar_id)
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -1892,6 +1894,7 @@ phypGetVIOSFreeSCSIAdapter(virConnectPtr conn)
     char *cmd = NULL;
     char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     if (system_type == HMC)
         virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
@@ -1916,7 +1919,7 @@ phypGetVIOSFreeSCSIAdapter(virConnectPtr conn)
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -2154,6 +2157,7 @@ phypVolumeGetKey(virConnectPtr conn, char *key, const char *name)
     char *cmd = NULL;
     char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     if (system_type == HMC)
         virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
@@ -2178,7 +2182,7 @@ phypVolumeGetKey(virConnectPtr conn, char *key, const char *name)
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -2209,6 +2213,7 @@ phypGetStoragePoolDevice(virConnectPtr conn, char *name)
     char *cmd = NULL;
     char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     if (system_type == HMC)
         virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
@@ -2233,7 +2238,7 @@ phypGetStoragePoolDevice(virConnectPtr conn, char *name)
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -2474,6 +2479,7 @@ phypVolumeGetPhysicalVolumeByStoragePool(virStorageVolPtr vol, char *sp)
     char *cmd = NULL;
     char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;

     if (system_type == HMC)
         virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
@@ -2498,7 +2504,7 @@ phypVolumeGetPhysicalVolumeByStoragePool(virStorageVolPtr vol, char *sp)
     if (exit_status < 0 || ret == NULL)
         goto err;

-    char *char_ptr = strchr(ret, '\n');
+    char_ptr = strchr(ret, '\n');

     if (char_ptr)
         *char_ptr = '\0';
@@ -2723,6 +2729,8 @@ phypVolumeGetPath(virStorageVolPtr vol)
     char *sp = NULL;
     char *path = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *char_ptr;
+    char *pv;

     if (system_type == HMC)
         virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
@@ -2748,12 +2756,12 @@ phypVolumeGetPath(virStorageVolPtr vol)
     if (exit_status < 0 || sp == NULL)
         goto err;

-    char *char_ptr = strchr(sp, '\n');
+    char_ptr = strchr(sp, '\n');

     if (char_ptr)
         *char_ptr = '\0';

-    char *pv = phypVolumeGetPhysicalVolumeByStoragePool(vol, sp);
+    pv = phypVolumeGetPhysicalVolumeByStoragePool(vol, sp);

     if (pv) {
         if (virAsprintf(&path, "/%s/%s/%s", pv, sp, vol->name) < 0) {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3138943..3d25ba4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3727,6 +3727,8 @@ qemuBuildCommandLine(virConnectPtr conn,
     for (i = 0 ; i < def->nchannels ; i++) {
         virDomainChrDefPtr channel = def->channels[i];
         char *devstr;
+        char *addr;
+        int port;

         switch(channel->targetType) {
         case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
@@ -3745,10 +3747,10 @@ qemuBuildCommandLine(virConnectPtr conn,
             virCommandAddArg(cmd, devstr);
             VIR_FREE(devstr);

-            char *addr = virSocketFormatAddr(channel->target.addr);
+            addr = virSocketFormatAddr(channel->target.addr);
             if (!addr)
                 goto error;
-            int port = virSocketGetPort(channel->target.addr);
+            port = virSocketGetPort(channel->target.addr);

             virCommandAddArg(cmd, "-netdev");
             virCommandAddArgFormat(cmd,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5aa715e..48fe266 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1426,6 +1426,7 @@ static int qemudDomainShutdown(virDomainPtr dom) {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int ret = -1;
+    qemuDomainObjPrivatePtr priv;

     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -1448,7 +1449,7 @@ static int qemudDomainShutdown(virDomainPtr dom) {
         goto endjob;
     }

-    qemuDomainObjPrivatePtr priv = vm->privateData;
+    priv = vm->privateData;
     qemuDomainObjEnterMonitor(vm);
     ret = qemuMonitorSystemPowerdown(priv->mon);
     qemuDomainObjExitMonitor(vm);
@@ -4748,6 +4749,7 @@ qemudDomainBlockStats (virDomainPtr dom,
     int i, ret = -1;
     virDomainObjPtr vm;
     virDomainDiskDefPtr disk = NULL;
+    qemuDomainObjPrivatePtr priv;

     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -4788,7 +4790,7 @@ qemudDomainBlockStats (virDomainPtr dom,
         goto endjob;
     }

-    qemuDomainObjPrivatePtr priv = vm->privateData;
+    priv = vm->privateData;
     qemuDomainObjEnterMonitor(vm);
     ret = qemuMonitorGetBlockStatsInfo(priv->mon,
                                        disk->info.alias,
@@ -4995,6 +4997,7 @@ qemudDomainMemoryPeek (virDomainPtr dom,
     virDomainObjPtr vm;
     char *tmp = NULL;
     int fd = -1, ret = -1;
+    qemuDomainObjPrivatePtr priv;

     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -5035,7 +5038,7 @@ qemudDomainMemoryPeek (virDomainPtr dom,
         goto endjob;
     }

-    qemuDomainObjPrivatePtr priv = vm->privateData;
+    priv = vm->privateData;
     qemuDomainObjEnterMonitor(vm);
     if (flags == VIR_MEMORY_VIRTUAL) {
         if (qemuMonitorSaveVirtualMemory(priv->mon, offset, size, tmp) < 0) {
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 9082515..b03f774 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -51,8 +51,8 @@ int qemuDomainChangeEjectableMedia(struct qemud_driver *driver,
     int i;
     int ret;
     char *driveAlias = NULL;
+    qemuDomainObjPrivatePtr priv;

-    origdisk = NULL;
     for (i = 0 ; i < vm->def->ndisks ; i++) {
         if (vm->def->disks[i]->bus == disk->bus &&
             STREQ(vm->def->disks[i]->dst, disk->dst)) {
@@ -90,7 +90,7 @@ int qemuDomainChangeEjectableMedia(struct qemud_driver *driver,
     if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, qemuCaps)))
         goto error;

-    qemuDomainObjPrivatePtr priv = vm->privateData;
+    priv = vm->privateData;
     qemuDomainObjEnterMonitorWithDriver(driver, vm);
     if (disk->src) {
         const char *format = NULL;
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 168c60f..53781c8 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1873,7 +1873,7 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
     if (qemuMonitorHMPCommand(mon, "info chardev", &reply) < 0) {
         qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
                         _("failed to retrieve chardev info in qemu with 'info chardev'"));
-        goto cleanup;
+        return -1;
     }

     char *pos;                          /* The current start of searching */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2fc2b6c..870d942 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1017,6 +1017,7 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
     int logfd;
     int ret = -1;
     virHashTablePtr paths = NULL;
+    qemuDomainObjPrivatePtr priv;

     if ((logfd = qemuProcessLogReadFD(driver->logDir, vm->def->name, pos)) < 0)
         return -1;
@@ -1039,7 +1040,7 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
     if (paths == NULL)
         goto cleanup;

-    qemuDomainObjPrivatePtr priv = vm->privateData;
+    priv = vm->privateData;
     qemuDomainObjEnterMonitorWithDriver(driver, vm);
     ret = qemuMonitorGetPtyPaths(priv->mon, paths);
     qemuDomainObjExitMonitorWithDriver(driver, vm);
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index bf94e70..166968a 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -869,12 +869,14 @@ doRemoteOpen (virConnectPtr conn,
         goto failed;

     /* Finally we can call the remote side's open function. */
-    remote_open_args args = { &name, flags };
+    {
+        remote_open_args args = { &name, flags };

-    if (call (conn, priv, REMOTE_CALL_IN_OPEN, REMOTE_PROC_OPEN,
-              (xdrproc_t) xdr_remote_open_args, (char *) &args,
-              (xdrproc_t) xdr_void, (char *) NULL) == -1)
-        goto failed;
+        if (call (conn, priv, REMOTE_CALL_IN_OPEN, REMOTE_PROC_OPEN,
+                  (xdrproc_t) xdr_remote_open_args, (char *) &args,
+                  (xdrproc_t) xdr_void, (char *) NULL) == -1)
+            goto failed;
+    }

     /* Now try and find out what URI the daemon used */
     if (conn->uri == NULL) {
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 587b3b5..d870616 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -95,8 +95,9 @@ SELinuxGenNewContext(const char *oldcontext, const char *mcs)
 {
     char *newcontext = NULL;
     char *scontext = strdup(oldcontext);
+    context_t con;
     if (!scontext) goto err;
-    context_t con = context_new(scontext);
+    con = context_new(scontext);
     if (!con) goto err;
     context_range_set(con, mcs);
     newcontext = strdup(context_str(con));
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 6eff5f5..f554537 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_iscsi.c: storage backend for iSCSI handling
  *
- * Copyright (C) 2007-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010-2011 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -269,6 +269,15 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
 {
     int ret = -1, exitstatus = -1;
     char temp_ifacename[32];
+    const char *const cmdargv1[] = {
+        ISCSIADM, "--mode", "iface", "--interface",
+        temp_ifacename, "--op", "new", NULL
+    };
+    const char *const cmdargv2[] = {
+        ISCSIADM, "--mode", "iface", "--interface", temp_ifacename,
+        "--op", "update", "--name", "iface.initiatorname", "--value",
+        initiatoriqn, NULL
+    };

     if (virRandomInitialize(time(NULL) ^ getpid()) == -1) {
         virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -277,12 +286,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
         goto out;
     }

-    snprintf(temp_ifacename, sizeof(temp_ifacename), "libvirt-iface-%08x", virRandom(1024 * 1024 * 1024));
-
-    const char *const cmdargv1[] = {
-        ISCSIADM, "--mode", "iface", "--interface",
-        &temp_ifacename[0], "--op", "new", NULL
-    };
+    snprintf(temp_ifacename, sizeof(temp_ifacename), "libvirt-iface-%08x",
+             virRandom(1024 * 1024 * 1024));

     VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
               &temp_ifacename[0], initiatoriqn);
@@ -298,12 +303,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
         goto out;
     }

-    const char *const cmdargv2[] = {
-        ISCSIADM, "--mode", "iface", "--interface", &temp_ifacename[0],
-        "--op", "update", "--name", "iface.initiatorname", "--value",
-        initiatoriqn, NULL
-    };
-
     /* Note that we ignore the exitstatus.  Older versions of iscsiadm tools
      * returned an exit status of > 0, even if they succeeded.  We will just
      * rely on whether iface file got updated properly. */
diff --git a/src/util/util.c b/src/util/util.c
index 43794b1..7384517 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -467,6 +467,7 @@ __virExec(const char *const*argv,
     int childerr = -1;
     int tmpfd;
     const char *binary = NULL;
+    int forkRet;

     if (argv[0][0] != '/') {
         if (!(binary = virFindFileInPath(argv[0]))) {
@@ -544,7 +545,7 @@ __virExec(const char *const*argv,
         childerr = null;
     }

-    int forkRet = virFork(&pid);
+    forkRet = virFork(&pid);

     if (pid < 0) {
         goto cleanup;
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 8bd27dd..0fbfba5 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -7186,12 +7186,15 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *
         }
     }
 #else /* VBOX_API_VERSION != 2002 */
-    IProgress *progress = NULL;
-    host->vtbl->CreateHostOnlyNetworkInterface(host, &networkInterface, &progress);
+    {
+        IProgress *progress = NULL;
+        host->vtbl->CreateHostOnlyNetworkInterface(host, &networkInterface,
+                                                   &progress);

-    if (progress) {
-        progress->vtbl->WaitForCompletion(progress, -1);
-        VBOX_RELEASE(progress);
+        if (progress) {
+            progress->vtbl->WaitForCompletion(progress, -1);
+            VBOX_RELEASE(progress);
+        }
     }
 #endif /* VBOX_API_VERSION != 2002 */

@@ -7342,6 +7345,8 @@ static virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) {
 static int vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) {
     VBOX_OBJECT_HOST_CHECK(network->conn, int, -1);
     char *networkNameUtf8 = NULL;
+    PRUnichar *networkInterfaceNameUtf16    = NULL;
+    IHostNetworkInterface *networkInterface = NULL;

     /* Current limitation of the function for VirtualBox 2.2.* is
      * that you can't delete the default hostonly adaptor namely:
@@ -7356,9 +7361,6 @@ static int vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterfac
         goto cleanup;
     }

-    PRUnichar *networkInterfaceNameUtf16    = NULL;
-    IHostNetworkInterface *networkInterface = NULL;
-
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);

     host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface);
@@ -7433,6 +7435,8 @@ static int vboxNetworkUndefine(virNetworkPtr network) {
 static int vboxNetworkCreate(virNetworkPtr network) {
     VBOX_OBJECT_HOST_CHECK(network->conn, int, -1);
     char *networkNameUtf8 = NULL;
+    PRUnichar *networkInterfaceNameUtf16    = NULL;
+    IHostNetworkInterface *networkInterface = NULL;

     /* Current limitation of the function for VirtualBox 2.2.* is
      * that the default hostonly network "vboxnet0" is always active
@@ -7446,9 +7450,6 @@ static int vboxNetworkCreate(virNetworkPtr network) {
         goto cleanup;
     }

-    PRUnichar *networkInterfaceNameUtf16    = NULL;
-    IHostNetworkInterface *networkInterface = NULL;
-
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);

     host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface);
@@ -7509,6 +7510,8 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
     virNetworkDefPtr def  = NULL;
     virNetworkIpDefPtr ipdef = NULL;
     char *networkNameUtf8 = NULL;
+    PRUnichar *networkInterfaceNameUtf16    = NULL;
+    IHostNetworkInterface *networkInterface = NULL;

     if (VIR_ALLOC(def) < 0) {
         virReportOOMError();
@@ -7526,9 +7529,6 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
         goto cleanup;
     }

-    PRUnichar *networkInterfaceNameUtf16    = NULL;
-    IHostNetworkInterface *networkInterface = NULL;
-
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);

     host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface);
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 27206a0..60b23c7 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -56,21 +56,24 @@
 static virCapsPtr
 getCapsObject (void)
 {
+    virCapsGuestPtr guest1, guest2;
+    virCapsGuestDomainPtr domain1, domain2;
     virCapsPtr caps = virCapabilitiesNew("x86_64", 0, 0);
+
     if (!caps) {
         virReportOOMError();
         return NULL;
     }
-    virCapsGuestPtr guest1 = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 0, "", "", 0, NULL);
+    guest1 = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 0, "", "", 0, NULL);
     if (!guest1)
         goto error_cleanup;
-    virCapsGuestDomainPtr domain1 = virCapabilitiesAddGuestDomain(guest1, "xen", "", "", 0, NULL);
+    domain1 = virCapabilitiesAddGuestDomain(guest1, "xen", "", "", 0, NULL);
     if (!domain1)
         goto error_cleanup;
-    virCapsGuestPtr guest2 = virCapabilitiesAddGuest(caps, "xen", "x86_64", 0, "", "", 0, NULL);
+    guest2 = virCapabilitiesAddGuest(caps, "xen", "x86_64", 0, "", "", 0, NULL);
     if (!guest2)
         goto error_cleanup;
-    virCapsGuestDomainPtr domain2 = virCapabilitiesAddGuestDomain(guest2, "xen", "", "", 0, NULL);
+    domain2 = virCapabilitiesAddGuestDomain(guest2, "xen", "", "", 0, NULL);
     if (!domain2)
         goto error_cleanup;

@@ -1234,6 +1237,12 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
     xen_string_string_map *result=NULL;
     xen_session *session = ((struct _xenapiPrivate *)(dom->conn->privateData))->session;
     virDomainDefPtr defPtr = NULL;
+    char *boot_policy = NULL;
+    unsigned long memory=0;
+    int64_t dynamic_mem=0;
+    char *val = NULL;
+    struct xen_vif_set *vif_set = NULL;
+    char *xml;

     if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL;
     if (vms->size != 1) {
@@ -1253,7 +1262,6 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
     memcpy(defPtr->uuid, dom->uuid, VIR_UUID_BUFLEN);
     if (!(defPtr->name = strdup(dom->name)))
         goto error_cleanup;
-    char *boot_policy = NULL;
     xen_vm_get_hvm_boot_policy(session, &boot_policy, vm);
     if (STREQ(boot_policy,"BIOS order")) {
         if (!(defPtr->os.type = strdup("hvm"))) {
@@ -1318,7 +1326,6 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
         if (!(defPtr->os.bootloader = strdup("pygrub")))
             goto error_cleanup;
     }
-    char *val = NULL;
     xen_vm_get_pv_bootloader_args(session, &val, vm);
     if (STRNEQ(val, "")) {
         if (!(defPtr->os.bootloaderArgs = strdup(val))) {
@@ -1327,10 +1334,8 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
         }
         VIR_FREE(val);
     }
-    unsigned long memory=0;
     memory = xenapiDomainGetMaxMemory(dom);
     defPtr->mem.max_balloon = memory;
-    int64_t dynamic_mem=0;
     if (xen_vm_get_memory_dynamic_max(session, &dynamic_mem, vm)) {
         defPtr->mem.cur_balloon = (unsigned long) (dynamic_mem / 1024);
     } else {
@@ -1365,7 +1370,6 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
         }
         xen_string_string_map_free(result);
     }
-    struct xen_vif_set *vif_set = NULL;
     xen_vm_get_vifs(session, &vif_set, vm);
     if (vif_set) {
         int i;
@@ -1403,7 +1407,7 @@ xenapiDomainDumpXML (virDomainPtr dom, int flags ATTRIBUTE_UNUSED)
         xen_vif_set_free(vif_set);
     }
     if (vms) xen_vm_set_free(vms);
-    char *xml = virDomainDefFormat(defPtr, 0);
+    xml = virDomainDefFormat(defPtr, 0);
     virDomainDefFree(defPtr);
     return xml;

diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 2ec5f9e..f50610a 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -1,5 +1,6 @@
 /*
  * xenapi_utils.c: Xen API driver -- utils parts.
+ * Copyright (C) 2011 Red Hat, Inc.
  * Copyright (C) 2009, 2010 Citrix Ltd.
  *
  * This library is free software; you can redistribute it and/or
@@ -462,6 +463,11 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,
                        xen_vm_record **record, xen_vm *vm)
 {
     char uuidStr[VIR_UUID_STRING_BUFLEN];
+    xen_string_string_map *strings = NULL;
+    int device_number = 0;
+    char *bridge = NULL, *mac = NULL;
+    int i;
+
     *record = xen_vm_record_alloc();
     if (!((*record)->name_label = strdup(def->name)))
         goto error_cleanup;
@@ -521,7 +527,6 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,
     if (def->onCrash)
         (*record)->actions_after_crash = actionCrashLibvirt2XenapiEnum(def->onCrash);

-    xen_string_string_map *strings = NULL;
     if (def->features) {
         if (def->features & (1 << VIR_DOMAIN_FEATURE_ACPI))
             allocStringMap(&strings, (char *)"acpi", (char *)"true");
@@ -546,9 +551,6 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,
         return -1;
     }

-    int device_number = 0;
-    char *bridge = NULL, *mac = NULL;
-    int i;
     for (i = 0; i < def->nnets; i++) {
         if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
             if (def->nets[i]->data.bridge.brname)
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]