[libvirt] [PATCH 31/34] vbox: use g_strdup instead of VIR_STRDUP

Ján Tomko jtomko at redhat.com
Sun Oct 20 12:55:49 UTC 2019


Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/vbox/vbox_XPCOMCGlue.c    |   3 +-
 src/vbox/vbox_common.c        | 147 ++++++++--------------------------
 src/vbox/vbox_network.c       |  45 +++++------
 src/vbox/vbox_snapshot_conf.c |  15 ++--
 src/vbox/vbox_storage.c       |  15 ++--
 5 files changed, 67 insertions(+), 158 deletions(-)

diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c
index 9310cace3e..a20b1c2a36 100644
--- a/src/vbox/vbox_XPCOMCGlue.c
+++ b/src/vbox/vbox_XPCOMCGlue.c
@@ -96,8 +96,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing,
             return -1;
         }
     } else {
-        if (VIR_STRDUP(name, DYNLIB_NAME) < 0)
-            return -1;
+        name = g_strdup(DYNLIB_NAME);
     }
 
     /*
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 94a79bde64..475b3a3147 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1625,23 +1625,13 @@ vboxAttachDisplay(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
         if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) &&
             (guiPresent == 0)) {
             guiPresent = 1;
-            if (VIR_STRDUP(guiDisplay, def->graphics[i]->data.desktop.display) < 0) {
-                /* just don't go to cleanup yet as it is ok to have
-                 * guiDisplay as NULL and we check it below if it
-                 * exist and then only use it there
-                 */
-            }
+            guiDisplay = g_strdup(def->graphics[i]->data.desktop.display);
         }
 
         if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) &&
             (sdlPresent == 0)) {
             sdlPresent = 1;
-            if (VIR_STRDUP(sdlDisplay, def->graphics[i]->data.sdl.display) < 0) {
-                /* just don't go to cleanup yet as it is ok to have
-                 * sdlDisplay as NULL and we check it below if it
-                 * exist and then only use it there
-                 */
-            }
+            sdlDisplay = g_strdup(def->graphics[i]->data.sdl.display);
         }
     }
 
@@ -2108,22 +2098,12 @@ vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, vboxIID *iid
 
             if (STREQ(valueTypeUtf8, "sdl")) {
                 sdlPresent = 1;
-                if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) {
-                    /* just don't go to cleanup yet as it is ok to have
-                     * sdlDisplay as NULL and we check it below if it
-                     * exist and then only use it there
-                     */
-                }
+                sdlDisplay = g_strdup(valueDisplayUtf8);
             }
 
             if (STREQ(valueTypeUtf8, "gui")) {
                 guiPresent = 1;
-                if (VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) {
-                    /* just don't go to cleanup yet as it is ok to have
-                     * guiDisplay as NULL and we check it below if it
-                     * exist and then only use it there
-                     */
-                }
+                guiDisplay = g_strdup(valueDisplayUtf8);
             }
         }
 
@@ -3546,9 +3526,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
             goto cleanup;
 
         graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
-        if (VIR_STRDUP(graphics->data.desktop.display,
-                       getenv("DISPLAY")) < 0)
-            goto cleanup;
+        graphics->data.desktop.display = g_strdup(getenv("DISPLAY"));
     }
 
     if (graphics &&
@@ -3641,21 +3619,13 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine
 
         gVBoxAPI.UISharedFolder.GetHostPath(sharedFolder, &hostPathUtf16);
         VBOX_UTF16_TO_UTF8(hostPathUtf16, &hostPath);
-        if (VIR_STRDUP(def->fss[i]->src->path, hostPath) < 0) {
-            VBOX_UTF8_FREE(hostPath);
-            VBOX_UTF16_FREE(hostPathUtf16);
-            goto cleanup;
-        }
+        def->fss[i]->src->path = g_strdup(hostPath);
         VBOX_UTF8_FREE(hostPath);
         VBOX_UTF16_FREE(hostPathUtf16);
 
         gVBoxAPI.UISharedFolder.GetName(sharedFolder, &nameUtf16);
         VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-        if (VIR_STRDUP(def->fss[i]->dst, name) < 0) {
-            VBOX_UTF8_FREE(name);
-            VBOX_UTF16_FREE(nameUtf16);
-            goto cleanup;
-        }
+        def->fss[i]->dst = g_strdup(name);
         VBOX_UTF8_FREE(name);
         VBOX_UTF16_FREE(nameUtf16);
 
@@ -3917,8 +3887,7 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine, PRUin
 
                 if (pathUtf16) {
                     VBOX_UTF16_TO_UTF8(pathUtf16, &path);
-                    if (VIR_STRDUP(def->serials[serialPortIncCount]->source->data.file.path, path) < 0)
-                        return -1;
+                    def->serials[serialPortIncCount]->source->data.file.path = g_strdup(path);
                 }
 
                 serialPortIncCount++;
@@ -4000,8 +3969,7 @@ vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine, PRU
                 gVBoxAPI.UIParallelPort.GetPath(parallelPort, &pathUtf16);
 
                 VBOX_UTF16_TO_UTF8(pathUtf16, &path);
-                if (VIR_STRDUP(def->parallels[parallelPortIncCount]->source->data.file.path, path) < 0)
-                    return -1;
+                def->parallels[parallelPortIncCount]->source->data.file.path = g_strdup(path);
 
                 parallelPortIncCount++;
 
@@ -4056,8 +4024,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     def->virtType = VIR_DOMAIN_VIRT_VBOX;
     def->id = dom->id;
     memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
-    if (VIR_STRDUP(def->name, dom->name) < 0)
-        goto cleanup;
+    def->name = g_strdup(dom->name);
 
     gVBoxAPI.UIMachine.GetMemorySize(machine, &memorySize);
     def->mem.cur_balloon = memorySize * 1024;
@@ -4218,14 +4185,7 @@ static int vboxConnectListDefinedDomains(virConnectPtr conn,
 
         gVBoxAPI.UIMachine.GetName(machine, &machineNameUtf16);
         VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
-        if (VIR_STRDUP(names[j], machineName) < 0) {
-            VBOX_UTF16_FREE(machineNameUtf16);
-            VBOX_UTF8_FREE(machineName);
-            for (j = 0; j < maxnames; j++)
-                VIR_FREE(names[j]);
-            ret = -1;
-            goto cleanup;
-        }
+        names[j] = g_strdup(machineName);
         VBOX_UTF16_FREE(machineNameUtf16);
         VBOX_UTF8_FREE(machineName);
         j++;
@@ -4897,10 +4857,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
 
         readOnlyDisk->format = format;
         readOnlyDisk->uuid = uuid;
-        if (VIR_STRDUP(readOnlyDisk->location, def->parent.dom->disks[it]->src->path) < 0) {
-            VIR_FREE(readOnlyDisk);
-            goto cleanup;
-        }
+        readOnlyDisk->location = g_strdup(def->parent.dom->disks[it]->src->path);
 
         if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(readOnlyDisk, snapshotMachineDesc->mediaRegistry,
                                        parentUuid) < 0) {
@@ -4998,23 +4955,18 @@ vboxSnapshotRedefine(virDomainPtr dom,
 
     char uuidtmp[VIR_UUID_STRING_BUFLEN];
     virUUIDFormat(snapshotUuid, uuidtmp);
-    if (VIR_STRDUP(newSnapshotPtr->uuid, uuidtmp) < 0)
-        goto cleanup;
+    newSnapshotPtr->uuid = g_strdup(uuidtmp);
 
     VIR_DEBUG("New snapshot UUID: %s", newSnapshotPtr->uuid);
-    if (VIR_STRDUP(newSnapshotPtr->name, def->parent.name) < 0)
-        goto cleanup;
+    newSnapshotPtr->name = g_strdup(def->parent.name);
 
     newSnapshotPtr->timeStamp = virTimeStringThen(def->parent.creationTime * 1000);
 
-    if (VIR_STRDUP(newSnapshotPtr->description, def->parent.description) < 0)
-        goto cleanup;
+    newSnapshotPtr->description = g_strdup(def->parent.description);
 
-    if (VIR_STRDUP(newSnapshotPtr->hardware, snapshotMachineDesc->hardware) < 0)
-        goto cleanup;
+    newSnapshotPtr->hardware = g_strdup(snapshotMachineDesc->hardware);
 
-    if (VIR_STRDUP(newSnapshotPtr->storageController, snapshotMachineDesc->storageController) < 0)
-        goto cleanup;
+    newSnapshotPtr->storageController = g_strdup(snapshotMachineDesc->storageController);
 
     /*We get the parent disk uuid from the parent disk location to correctly fill the storage controller.*/
     for (it = 0; it < def->parent.dom->ndisks; it++) {
@@ -5045,8 +4997,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
         VIR_FREE(newSnapshotPtr->storageController);
         if (!tmp)
             goto cleanup;
-        if (VIR_STRDUP(newSnapshotPtr->storageController, tmp) < 0)
-            goto cleanup;
+        newSnapshotPtr->storageController = g_strdup(tmp);
 
         VIR_FREE(tmp);
     }
@@ -5146,10 +5097,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
             disk->format = format;
             VBOX_UTF16_FREE(formatUtf16);
 
-            if (VIR_STRDUP(disk->location, def->disks[it].src->path) < 0) {
-                VIR_FREE(disk);
-                goto cleanup;
-            }
+            disk->location = g_strdup(def->disks[it].src->path);
 
             rc = gVBoxAPI.UIMedium.GetId(medium, &iid);
             if (NS_FAILED(rc)) {
@@ -5201,8 +5149,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
                 VIR_FREE(snapshotMachineDesc->storageController);
                 if (!tmp)
                     goto cleanup;
-                if (VIR_STRDUP(snapshotMachineDesc->storageController, tmp) < 0)
-                    goto cleanup;
+                snapshotMachineDesc->storageController = g_strdup(tmp);
 
                 VIR_FREE(tmp);
             }
@@ -5308,8 +5255,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
             newHardDisk->uuid = uuid;
             vboxIIDUnalloc(&iid);
 
-            if (VIR_STRDUP(newHardDisk->location, newLocationUtf8) < 0)
-                goto cleanup;
+            newHardDisk->location = g_strdup(newLocationUtf8);
 
             rc = gVBoxAPI.UIMedium.GetFormat(newMedium, &formatUtf16);
             VBOX_UTF16_TO_UTF8(formatUtf16, &format);
@@ -5342,8 +5288,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
             VIR_FREE(snapshotMachineDesc->storageController);
             if (!tmp)
                 goto cleanup;
-            if (VIR_STRDUP(snapshotMachineDesc->storageController, tmp) < 0)
-                goto cleanup;
+            snapshotMachineDesc->storageController = g_strdup(tmp);
 
             VIR_FREE(tmp);
             /*Closing the "fake" disk*/
@@ -5922,12 +5867,7 @@ vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
                     }
                     VBOX_UTF16_TO_UTF8(childLocUtf16, &childLocUtf8);
                     VBOX_UTF16_FREE(childLocUtf16);
-                    if (VIR_STRDUP(def->disks[diskCount].src->path, childLocUtf8) < 0) {
-                        VBOX_RELEASE(storageController);
-                        VBOX_RELEASE(disk);
-                        VBOX_RELEASE(child);
-                        goto cleanup;
-                    }
+                    def->disks[diskCount].src->path = g_strdup(childLocUtf8);
                     VBOX_UTF8_FREE(childLocUtf8);
 
                     def->disks[diskCount].src->type = VIR_STORAGE_TYPE_FILE;
@@ -6116,8 +6056,7 @@ vboxSnapshotGetReadOnlyDisks(virDomainSnapshotDefPtr def,
         }
         VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8);
         VBOX_UTF16_FREE(mediumLocUtf16);
-        if (VIR_STRDUP(defdom->disks[diskCount]->src->path, mediumLocUtf8) < 0)
-            goto cleanup;
+        defdom->disks[diskCount]->src->path = g_strdup(mediumLocUtf8);
 
         VBOX_UTF8_FREE(mediumLocUtf8);
         rc = gVBoxAPI.UIMedium.GetReadOnly(disk, &readOnly);
@@ -6217,8 +6156,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         !(def->parent.dom = virDomainDefNew()))
         goto cleanup;
     defdom = def->parent.dom;
-    if (VIR_STRDUP(def->parent.name, snapshot->name) < 0)
-        goto cleanup;
+    def->parent.name = g_strdup(snapshot->name);
 
     if (gVBoxAPI.vboxSnapshotRedefine) {
         /* Register def->dom properties for them to be saved inside the snapshot XMl
@@ -6230,8 +6168,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         defdom->virtType = VIR_DOMAIN_VIRT_VBOX;
         defdom->id = dom->id;
         memcpy(defdom->uuid, dom->uuid, VIR_UUID_BUFLEN);
-        if (VIR_STRDUP(defdom->name, dom->name) < 0)
-            goto cleanup;
+        defdom->name = g_strdup(dom->name);
         gVBoxAPI.UIMachine.GetMemorySize(machine, &memorySize);
         defdom->mem.cur_balloon = memorySize * 1024;
         /* Currently setting memory and maxMemory as same, cause
@@ -6265,10 +6202,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
     if (str16) {
         VBOX_UTF16_TO_UTF8(str16, &str8);
         VBOX_UTF16_FREE(str16);
-        if (VIR_STRDUP(def->parent.description, str8) < 0) {
-            VBOX_UTF8_FREE(str8);
-            goto cleanup;
-        }
+        def->parent.description = g_strdup(str8);
         VBOX_UTF8_FREE(str8);
     }
 
@@ -6299,10 +6233,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         }
         VBOX_UTF16_TO_UTF8(str16, &str8);
         VBOX_UTF16_FREE(str16);
-        if (VIR_STRDUP(def->parent.parent_name, str8) < 0) {
-            VBOX_UTF8_FREE(str8);
-            goto cleanup;
-        }
+        def->parent.parent_name = g_strdup(str8);
         VBOX_UTF8_FREE(str8);
     }
 
@@ -6433,10 +6364,7 @@ static int vboxDomainSnapshotListNames(virDomainPtr dom, char **names,
         }
         VBOX_UTF16_TO_UTF8(nameUtf16, &name);
         VBOX_UTF16_FREE(nameUtf16);
-        if (VIR_STRDUP(names[i], name) < 0) {
-            VBOX_UTF8_FREE(name);
-            goto cleanup;
-        }
+        names[i] = g_strdup(name);
         VBOX_UTF8_FREE(name);
     }
 
@@ -7100,10 +7028,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
                 disk->uuid = uuid;
                 vboxIIDUnalloc(&iid);
 
-                if (VIR_STRDUP(disk->location, newLocationUtf8) < 0) {
-                    VIR_FREE(disk);
-                    goto cleanup;
-                }
+                disk->location = g_strdup(newLocationUtf8);
 
                 rc = gVBoxAPI.UIMedium.GetFormat(newMedium, &formatUtf16);
                 VBOX_UTF16_TO_UTF8(formatUtf16, &format);
@@ -7135,8 +7060,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
                 VIR_FREE(snapshotMachineDesc->storageController);
                 if (!tmp)
                     goto cleanup;
-                if (VIR_STRDUP(snapshotMachineDesc->storageController, tmp) < 0)
-                    goto cleanup;
+                snapshotMachineDesc->storageController = g_strdup(tmp);
 
                 VIR_FREE(tmp);
                 /*Closing the "fake" disk*/
@@ -7178,8 +7102,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
                 VIR_FREE(snapshotMachineDesc->storageController);
                 if (!tmp)
                     goto cleanup;
-                if (VIR_STRDUP(snapshotMachineDesc->storageController, tmp) < 0)
-                    goto cleanup;
+                snapshotMachineDesc->storageController = g_strdup(tmp);
 
                 VIR_FREE(tmp);
             }
@@ -7289,8 +7212,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
                                _("Unable to get the snapshot to remove"));
                 goto cleanup;
             }
-            if (VIR_STRDUP(snapshotMachineDesc->currentSnapshot, snap->uuid) < 0)
-                goto cleanup;
+            snapshotMachineDesc->currentSnapshot = g_strdup(snap->uuid);
         }
     }
 
@@ -7528,8 +7450,7 @@ vboxDomainScreenshot(virDomainPtr dom,
                     goto endjob;
                 }
 
-                if (VIR_STRDUP(ret, "image/png") < 0)
-                    goto endjob;
+                ret = g_strdup("image/png");
 
                 if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
                     virReportError(VIR_ERR_OPERATION_FAILED, "%s",
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index 814f27155f..9e632ab709 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -132,8 +132,8 @@ static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int n
         VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
 
         VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
-        if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
-            ret++;
+        names[ret] = g_strdup(nameUtf8);
+        ret++;
 
         VBOX_UTF8_FREE(nameUtf8);
         VBOX_UTF16_FREE(nameUtf16);
@@ -234,8 +234,8 @@ static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names
         VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
 
         VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
-        if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
-            ret++;
+        names[ret] = g_strdup(nameUtf8);
+        ret++;
 
         VBOX_UTF8_FREE(nameUtf8);
         VBOX_UTF16_FREE(nameUtf16);
@@ -806,8 +806,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
     if (interfaceType != HostNetworkInterfaceType_HostOnly)
         goto cleanup;
 
-    if (VIR_STRDUP(def->name, network->name) < 0)
-        goto cleanup;
+    def->name = g_strdup(network->name);
 
     rc = gVBoxAPI.UIHNInterface.GetId(networkInterface, &vboxnet0IID);
     if (NS_FAILED(rc))
@@ -861,30 +860,26 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
 
         ipdef->nhosts = 1;
         if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >= 0) {
-            if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) {
-                VIR_FREE(ipdef->hosts);
-                ipdef->nhosts = 0;
-            } else {
-                PRUnichar *macAddressUtf16 = NULL;
-                PRUnichar *ipAddressUtf16 = NULL;
-                bool errorOccurred = false;
+            PRUnichar *macAddressUtf16 = NULL;
+            PRUnichar *ipAddressUtf16 = NULL;
+            bool errorOccurred = false;
 
-                gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, &macAddressUtf16);
-                gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, &ipAddressUtf16);
+            ipdef->hosts[0].name = g_strdup(network->name);
+            gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, &macAddressUtf16);
+            gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, &ipAddressUtf16);
 
-                VBOX_UTF16_TO_UTF8(macAddressUtf16, &ipdef->hosts[0].mac);
+            VBOX_UTF16_TO_UTF8(macAddressUtf16, &ipdef->hosts[0].mac);
 
-                if (vboxSocketParseAddrUtf16(data, ipAddressUtf16,
-                                             &ipdef->hosts[0].ip) < 0) {
-                    errorOccurred = true;
-                }
+            if (vboxSocketParseAddrUtf16(data, ipAddressUtf16,
+                                         &ipdef->hosts[0].ip) < 0) {
+                errorOccurred = true;
+            }
 
-                VBOX_UTF16_FREE(macAddressUtf16);
-                VBOX_UTF16_FREE(ipAddressUtf16);
+            VBOX_UTF16_FREE(macAddressUtf16);
+            VBOX_UTF16_FREE(ipAddressUtf16);
 
-                if (errorOccurred)
-                    goto cleanup;
-            }
+            if (errorOccurred)
+                goto cleanup;
         } else {
             ipdef->nhosts = 0;
         }
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index a6daf0ffcf..8cdfb35357 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -74,8 +74,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlNodePtr diskNode,
                        _("Cannot parse <HardDisk> 'uuid' attribute"));
         goto cleanup;
     }
-    if (VIR_STRDUP(hardDisk->uuid, searchTabResult[0]) < 0)
-        goto cleanup;
+    hardDisk->uuid = g_strdup(searchTabResult[0]);
 
     location = virXMLPropString(diskNode, "location");
     if (location == NULL) {
@@ -87,11 +86,9 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlNodePtr diskNode,
         /*The location is a relative path, so we must change it into an absolute one. */
         if (virAsprintf(&tmp, "%s%s", machineLocation, location) < 0)
             goto cleanup;
-        if (VIR_STRDUP(hardDisk->location, tmp) < 0)
-            goto cleanup;
+        hardDisk->location = g_strdup(tmp);
     } else {
-        if (VIR_STRDUP(hardDisk->location, location) < 0)
-            goto cleanup;
+        hardDisk->location = g_strdup(location);
     }
     hardDisk->format = virXMLPropString(diskNode, "format");
     if (hardDisk->format == NULL) {
@@ -208,8 +205,7 @@ virVBoxSnapshotConfRetrieveSnapshot(xmlNodePtr snapshotNode,
                        _("Cannot parse <Snapshot> 'uuid' attribute"));
         goto cleanup;
     }
-    if (VIR_STRDUP(snapshot->uuid, searchTabResult[0]) < 0)
-        goto cleanup;
+    snapshot->uuid = g_strdup(searchTabResult[0]);
 
     snapshot->name = virXMLPropString(snapshotNode, "name");
     if (snapshot->name == NULL) {
@@ -662,8 +658,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
                            _("Cannot parse <Machine> 'currentSnapshot' attribute"));
             goto cleanup;
         }
-        if (VIR_STRDUP(machineDescription->currentSnapshot, searchResultTab[0]) < 0)
-            goto cleanup;
+        machineDescription->currentSnapshot = g_strdup(searchResultTab[0]);
     }
 
     machineDescription->snapshotFolder = virXMLPropString(machineNode, "snapshotFolder");
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
index 6929a9a2f3..c7bea2c219 100644
--- a/src/vbox/vbox_storage.c
+++ b/src/vbox/vbox_storage.c
@@ -56,9 +56,10 @@ static int vboxConnectListStoragePools(virConnectPtr conn G_GNUC_UNUSED,
 {
     int numActive = 0;
 
-    if (nnames > 0 &&
-        VIR_STRDUP(names[numActive], "default-pool") > 0)
+    if (nnames > 0) {
+        names[numActive] = g_strdup("default-pool");
         numActive++;
+    }
     return numActive;
 }
 
@@ -167,8 +168,8 @@ vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nname
             continue;
 
         VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8);
-        if (VIR_STRDUP(names[numActive], nameUtf8) > 0)
-            numActive++;
+        names[numActive] = g_strdup(nameUtf8);
+        numActive++;
 
         VBOX_UTF8_FREE(nameUtf8);
     }
@@ -770,11 +771,9 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
     if (NS_FAILED(rc))
         goto cleanup;
 
-    if (VIR_STRDUP(def.name, vol->name) < 0)
-        goto cleanup;
+    def.name = g_strdup(vol->name);
 
-    if (VIR_STRDUP(def.key, vol->key) < 0)
-        goto cleanup;
+    def.key = g_strdup(vol->key);
 
     rc = gVBoxAPI.UIMedium.GetFormat(hardDisk, &hddFormatUtf16);
     if (NS_FAILED(rc))
-- 
2.21.0




More information about the libvir-list mailing list