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

[libvirt] [PATCH v2 27/37] Adapt to VIR_STRDUP in src/vbox/*



---
 src/vbox/vbox_XPCOMCGlue.c |   4 +-
 src/vbox/vbox_tmpl.c       | 190 +++++++++++++++++++++++----------------------
 2 files changed, 98 insertions(+), 96 deletions(-)

diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c
index e0b606f..c5500b9 100644
--- a/src/vbox/vbox_XPCOMCGlue.c
+++ b/src/vbox/vbox_XPCOMCGlue.c
@@ -105,9 +105,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing,
             return -1;
         }
     } else {
-        name = strdup(DYNLIB_NAME);
-
-        if (name == NULL) {
+        if (VIR_STRDUP(name, DYNLIB_NAME) < 0) {
             virReportOOMError();
             return -1;
         }
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 43ddac8..0e80194 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1840,9 +1840,9 @@ static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
      * is supposed to pass the ABI name and not the domain
      * operating system driver as I had imagined ;)
      */
-    char *osType = strdup("hvm");
+    char *osType;
 
-    if (osType == NULL)
+    if (VIR_STRDUP(osType, "hvm") < 0)
         virReportOOMError();
 
     return osType;
@@ -2290,7 +2290,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);
-            def->name = strdup(dom->name);
+            ignore_value(VIR_STRDUP(def->name, dom->name));
 
             machine->vtbl->GetMemorySize(machine, &memorySize);
             def->mem.cur_balloon = memorySize * 1024;
@@ -2325,7 +2325,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
             /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
 
-            def->os.type = strdup("hvm");
+            ignore_value(VIR_STRDUP(def->os.type, "hvm"));
 
             def->os.arch = virArchFromHost();
 
@@ -2460,9 +2460,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                         if (STREQ(valueTypeUtf8, "sdl")) {
                             sdlPresent = 1;
-                            if (valueDisplayUtf8)
-                                sdlDisplay = strdup(valueDisplayUtf8);
-                            if (sdlDisplay == NULL) {
+                            if (valueDisplayUtf8 &&
+                                VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) {
                                 virReportOOMError();
                                 /* just don't go to cleanup yet as it is ok to have
                                  * sdlDisplay as NULL and we check it below if it
@@ -2474,9 +2473,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                         if (STREQ(valueTypeUtf8, "gui")) {
                             guiPresent = 1;
-                            if (valueDisplayUtf8)
-                                guiDisplay = strdup(valueDisplayUtf8);
-                            if (guiDisplay == NULL) {
+                            if (valueDisplayUtf8 &&
+                                VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) {
                                 virReportOOMError();
                                 /* just don't go to cleanup yet as it is ok to have
                                  * guiDisplay as NULL and we check it below if it
@@ -2513,8 +2511,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
                         def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
                         tmp = getenv("DISPLAY");
                         if (tmp != NULL) {
-                            def->graphics[def->ngraphics]->data.desktop.display = strdup(tmp);
-                            if (def->graphics[def->ngraphics]->data.desktop.display == NULL) {
+                            if (VIR_STRDUP(def->graphics[def->ngraphics]->data.desktop.display, tmp) < 0) {
                                 virReportOOMError();
                                 /* just don't go to cleanup yet as it is ok to have
                                  * display as NULL
@@ -2649,8 +2646,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                 if (hddType == HardDiskType_Immutable)
                     def->disks[hddNum]->readonly = true;
-                def->disks[hddNum]->src = strdup(hddlocation);
-                def->disks[hddNum]->dst = strdup("hda");
+                if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 ||
+                    VIR_STRDUP(def->disks[hddNum]->dst, "hda") < 0)
+                    virReportOOMError();
                 hddNum++;
 
                 VBOX_UTF8_FREE(hddlocation);
@@ -2670,8 +2668,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                 if (hddType == HardDiskType_Immutable)
                     def->disks[hddNum]->readonly = true;
-                def->disks[hddNum]->src = strdup(hddlocation);
-                def->disks[hddNum]->dst = strdup("hdb");
+                if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 ||
+                    VIR_STRDUP(def->disks[hddNum]->dst, "hdb") < 0)
+                    virReportOOMError();
                 hddNum++;
 
                 VBOX_UTF8_FREE(hddlocation);
@@ -2691,8 +2690,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                 if (hddType == HardDiskType_Immutable)
                     def->disks[hddNum]->readonly = true;
-                def->disks[hddNum]->src = strdup(hddlocation);
-                def->disks[hddNum]->dst = strdup("hdd");
+                if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 ||
+                    VIR_STRDUP(def->disks[hddNum]->dst, "hdd") < 0)
+                    virReportOOMError();
                 hddNum++;
 
                 VBOX_UTF8_FREE(hddlocation);
@@ -2780,7 +2780,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
                 medium->vtbl->GetLocation(medium, &mediumLocUtf16);
                 VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8);
                 VBOX_UTF16_FREE(mediumLocUtf16);
-                def->disks[diskCount]->src = strdup(mediumLocUtf8);
+                if (VIR_STRDUP(def->disks[diskCount]->src, mediumLocUtf8) < 0)
+                    virReportOOMError();
                 VBOX_UTF8_FREE(mediumLocUtf8);
 
                 if (!(def->disks[diskCount]->src)) {
@@ -2884,7 +2885,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                     sharedFolder->vtbl->GetHostPath(sharedFolder, &hostPathUtf16);
                     VBOX_UTF16_TO_UTF8(hostPathUtf16, &hostPath);
-                    def->fss[i]->src = strdup(hostPath);
+                    if (VIR_STRDUP(def->fss[i]->src, hostPath) < 0)
+                        virReportOOMError();
                     VBOX_UTF8_FREE(hostPath);
                     VBOX_UTF16_FREE(hostPathUtf16);
 
@@ -2895,7 +2897,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
 
                     sharedFolder->vtbl->GetName(sharedFolder, &nameUtf16);
                     VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-                    def->fss[i]->dst = strdup(name);
+                    if (VIR_STRDUP(def->fss[i]->dst, name) < 0)
+                        virReportOOMError();
                     VBOX_UTF8_FREE(name);
                     VBOX_UTF16_FREE(nameUtf16);
 
@@ -2957,6 +2960,7 @@ sharedFoldersCleanup:
                         PRUnichar *MACAddressUtf16 = NULL;
                         char *MACAddress           = NULL;
                         char macaddr[VIR_MAC_STRING_BUFLEN] = {0};
+                        int strdupRet = 0;
 
                         adapter->vtbl->GetAttachmentType(adapter, &attachmentType);
                         if (attachmentType == NetworkAttachmentType_NAT) {
@@ -2976,8 +2980,8 @@ sharedFoldersCleanup:
 #endif /* VBOX_API_VERSION >= 4001 */
 
                             VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
-                            def->nets[netAdpIncCnt]->data.bridge.brname = strdup(hostInt);
-
+                            if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.bridge.brname, hostInt) < 0)
+                                virReportOOMError();
                             VBOX_UTF8_FREE(hostInt);
                             VBOX_UTF16_FREE(hostIntUtf16);
 
@@ -2990,8 +2994,8 @@ sharedFoldersCleanup:
                             adapter->vtbl->GetInternalNetwork(adapter, &intNetUtf16);
 
                             VBOX_UTF16_TO_UTF8(intNetUtf16, &intNet);
-                            def->nets[netAdpIncCnt]->data.internal.name = strdup(intNet);
-
+                            if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.internal.name, intNet) < 0)
+                                virReportOOMError();
                             VBOX_UTF8_FREE(intNet);
                             VBOX_UTF16_FREE(intNetUtf16);
 
@@ -3008,8 +3012,8 @@ sharedFoldersCleanup:
 #endif /* VBOX_API_VERSION >= 4001 */
 
                             VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
-                            def->nets[netAdpIncCnt]->data.network.name = strdup(hostInt);
-
+                            if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.network.name, hostInt) < 0)
+                                virReportOOMError();
                             VBOX_UTF8_FREE(hostInt);
                             VBOX_UTF16_FREE(hostIntUtf16);
 
@@ -3022,21 +3026,24 @@ sharedFoldersCleanup:
 
                         adapter->vtbl->GetAdapterType(adapter, &adapterType);
                         if (adapterType == NetworkAdapterType_Am79C970A) {
-                            def->nets[netAdpIncCnt]->model = strdup("Am79C970A");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C970A");
                         } else if (adapterType == NetworkAdapterType_Am79C973) {
-                            def->nets[netAdpIncCnt]->model = strdup("Am79C973");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C973");
                         } else if (adapterType == NetworkAdapterType_I82540EM) {
-                            def->nets[netAdpIncCnt]->model = strdup("82540EM");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82540EM");
                         } else if (adapterType == NetworkAdapterType_I82545EM) {
-                            def->nets[netAdpIncCnt]->model = strdup("82545EM");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82545EM");
                         } else if (adapterType == NetworkAdapterType_I82543GC) {
-                            def->nets[netAdpIncCnt]->model = strdup("82543GC");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82543GC");
 #if VBOX_API_VERSION >= 3001
                         } else if (adapterType == NetworkAdapterType_Virtio) {
-                            def->nets[netAdpIncCnt]->model = strdup("virtio");
+                            strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "virtio");
 #endif /* VBOX_API_VERSION >= 3001 */
                         }
 
+                        if (strdupRet < 0)
+                            virReportOOMError();
+
                         adapter->vtbl->GetMACAddress(adapter, &MACAddressUtf16);
                         VBOX_UTF16_TO_UTF8(MACAddressUtf16, &MACAddress);
                         snprintf(macaddr, VIR_MAC_STRING_BUFLEN,
@@ -3120,8 +3127,9 @@ sharedFoldersCleanup:
                                 def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE;
                                 def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE;
                                 def->disks[def->ndisks - 1]->readonly = true;
-                                def->disks[def->ndisks - 1]->src = strdup(location);
-                                def->disks[def->ndisks - 1]->dst = strdup("hdc");
+                                if (VIR_STRDUP(def->disks[def->ndisks - 1]->src, location) < 0 ||
+                                    VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "hdc") < 0)
+                                    virReportOOMError();
                             } else {
                                 def->ndisks--;
                                 virReportOOMError();
@@ -3167,8 +3175,9 @@ sharedFoldersCleanup:
                                     def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC;
                                     def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE;
                                     def->disks[def->ndisks - 1]->readonly = false;
-                                    def->disks[def->ndisks - 1]->src = strdup(location);
-                                    def->disks[def->ndisks - 1]->dst = strdup("fda");
+                                    if (VIR_STRDUP(def->disks[def->ndisks - 1]->src, location) < 0 ||
+                                        VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "fda") < 0)
+                                        virReportOOMError();
                                 } else {
                                     def->ndisks--;
                                     virReportOOMError();
@@ -3261,7 +3270,8 @@ sharedFoldersCleanup:
 
                         if (pathUtf16) {
                             VBOX_UTF16_TO_UTF8(pathUtf16, &path);
-                            def->serials[serialPortIncCount]->source.data.file.path = strdup(path);
+                            if (VIR_STRDUP(def->serials[serialPortIncCount]->source.data.file.path, path) < 0)
+                                virReportOOMError();
                         }
 
                         serialPortIncCount++;
@@ -3331,7 +3341,8 @@ sharedFoldersCleanup:
                         parallelPort->vtbl->GetPath(parallelPort, &pathUtf16);
 
                         VBOX_UTF16_TO_UTF8(pathUtf16, &path);
-                        def->parallels[parallelPortIncCount]->source.data.file.path = strdup(path);
+                        if (VIR_STRDUP(def->parallels[parallelPortIncCount]->source.data.file.path, path) < 0)
+                            virReportOOMError();
 
                         parallelPortIncCount++;
 
@@ -3478,7 +3489,8 @@ static int vboxConnectListDefinedDomains(virConnectPtr conn, char ** const names
                     (state > MachineState_LastOnline)) {
                     machine->vtbl->GetName(machine, &machineNameUtf16);
                     VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
-                    names[j] = strdup(machineName);
+                    if (VIR_STRDUP(names[j], machineName) < 0)
+                        virReportOOMError();
                     VBOX_UTF16_FREE(machineNameUtf16);
                     VBOX_UTF8_FREE(machineName);
                     if (!names[j]) {
@@ -3585,8 +3597,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
             if (STREQ(valueTypeUtf8, "sdl")) {
                 sdlPresent = 1;
                 if (valueDisplayUtf8) {
-                    sdlDisplay = strdup(valueDisplayUtf8);
-                    if (sdlDisplay == NULL) {
+                    if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) {
                         virReportOOMError();
                         /* just don't go to cleanup yet as it is ok to have
                          * sdlDisplay as NULL and we check it below if it
@@ -3599,8 +3610,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
             if (STREQ(valueTypeUtf8, "gui")) {
                 guiPresent = 1;
                 if (valueDisplayUtf8) {
-                    guiDisplay = strdup(valueDisplayUtf8);
-                    if (guiDisplay == NULL) {
+                    if (VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) {
                         virReportOOMError();
                         /* just don't go to cleanup yet as it is ok to have
                          * guiDisplay as NULL and we check it below if it
@@ -3982,7 +3992,10 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
                                 PRInt32 device           = 0;
                                 PRUnichar *hddcnameUtf16 = NULL;
 
-                                char *hddcname = strdup("IDE");
+                                char *hddcname;
+
+                                if (VIR_STRDUP(hddcname, "IDE") < 0)
+                                    virReportOOMError();
                                 VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16);
                                 VIR_FREE(hddcname);
 
@@ -4802,8 +4815,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
             (guiPresent == 0)) {
             guiPresent = 1;
             if (def->graphics[i]->data.desktop.display) {
-                guiDisplay = strdup(def->graphics[i]->data.desktop.display);
-                if (guiDisplay == NULL) {
+                if (VIR_STRDUP(guiDisplay, def->graphics[i]->data.desktop.display) < 0) {
                     virReportOOMError();
                     /* just don't go to cleanup yet as it is ok to have
                      * guiDisplay as NULL and we check it below if it
@@ -4817,8 +4829,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
             (sdlPresent == 0)) {
             sdlPresent = 1;
             if (def->graphics[i]->data.sdl.display) {
-                sdlDisplay = strdup(def->graphics[i]->data.sdl.display);
-                if (sdlDisplay == NULL) {
+                if (VIR_STRDUP(sdlDisplay, def->graphics[i]->data.sdl.display) < 0) {
                     virReportOOMError();
                     /* just don't go to cleanup yet as it is ok to have
                      * sdlDisplay as NULL and we check it below if it
@@ -5226,7 +5237,10 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
     {
         PRUnichar *hddcnameUtf16 = NULL;
 
-        char *hddcname = strdup("IDE");
+        char *hddcname;
+
+        if (VIR_STRDUP(hddcname, "IDE") < 0)
+            virReportOOMError();
         VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16);
         VIR_FREE(hddcname);
 
@@ -5385,9 +5399,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
         return ret;
     }
 
-    def->os.type = strdup("hvm");
-
-    if (def->os.type == NULL) {
+    if (VIR_STRDUP(def->os.type, "hvm") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -5620,9 +5632,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) {
         return ret;
     }
 
-    def->os.type = strdup("hvm");
-
-    if (def->os.type == NULL) {
+    if (VIR_STRDUP(def->os.type, "hvm") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -6051,7 +6061,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         goto cleanup;
 
     if (VIR_ALLOC(def) < 0
-        || !(def->name = strdup(snapshot->name)))
+        || VIR_STRDUP(def->name, snapshot->name) < 0)
         goto no_memory;
 
     rc = snap->vtbl->GetDescription(snap, &str16);
@@ -6064,10 +6074,12 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
     if (str16) {
         VBOX_UTF16_TO_UTF8(str16, &str8);
         VBOX_UTF16_FREE(str16);
-        def->description = strdup(str8);
-        VBOX_UTF8_FREE(str8);
-        if (!def->description)
+        if (VIR_STRDUP(def->description, str8) < 0) {
+            virReportOOMError();
+            VBOX_UTF8_FREE(str8);
             goto no_memory;
+        }
+        VBOX_UTF8_FREE(str8);
     }
 
     rc = snap->vtbl->GetTimeStamp(snap, &timestamp);
@@ -6097,10 +6109,12 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         }
         VBOX_UTF16_TO_UTF8(str16, &str8);
         VBOX_UTF16_FREE(str16);
-        def->parent = strdup(str8);
-        VBOX_UTF8_FREE(str8);
-        if (!def->parent)
+        if (VIR_STRDUP(def->parent, str8) < 0) {
+            virReportOOMError();
+            VBOX_UTF8_FREE(str8);
             goto no_memory;
+        }
+        VBOX_UTF8_FREE(str8);
     }
 
     rc = snap->vtbl->GetOnline(snap, &online);
@@ -6247,12 +6261,12 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
         }
         VBOX_UTF16_TO_UTF8(nameUtf16, &name);
         VBOX_UTF16_FREE(nameUtf16);
-        names[i] = strdup(name);
-        VBOX_UTF8_FREE(name);
-        if (!names[i]) {
+        if (VIR_STRDUP(names[i], name) < 0) {
             virReportOOMError();
+            VBOX_UTF8_FREE(name);
             goto cleanup;
         }
+        VBOX_UTF8_FREE(name);
     }
 
     if (count <= nameslen)
@@ -7529,12 +7543,10 @@ static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int n
                     VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
 
                     VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
-                    names[ret] = strdup(nameUtf8);
-                    if (names[ret] == NULL) {
+                    if (VIR_STRDUP(names[ret], nameUtf8) < 0)
                         virReportOOMError();
-                    } else {
+                    else
                         ret++;
-                    }
 
                     VBOX_UTF8_FREE(nameUtf8);
                     VBOX_UTF16_FREE(nameUtf16);
@@ -7611,12 +7623,10 @@ static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names
                     VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
 
                     VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
-                    names[ret] = strdup(nameUtf8);
-                    if (names[ret] == NULL) {
+                    if (VIR_STRDUP(names[ret], nameUtf8) < 0)
                         virReportOOMError();
-                    } else {
+                    else
                         ret++;
-                    }
 
                     VBOX_UTF8_FREE(nameUtf8);
                     VBOX_UTF16_FREE(nameUtf16);
@@ -8117,8 +8127,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
         networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
 
         if (interfaceType == HostNetworkInterfaceType_HostOnly) {
-            def->name = strdup(network->name);
-            if (def->name != NULL) {
+            if (VIR_STRDUP(def->name, network->name) == 0) {
                 PRUnichar *networkNameUtf16 = NULL;
                 IDHCPServer *dhcpServer     = NULL;
                 vboxIID vboxnet0IID = VBOX_IID_INITIALIZER;
@@ -8175,8 +8184,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
 
                     ipdef->nhosts = 1;
                     if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >=0) {
-                        ipdef->hosts[0].name = strdup(network->name);
-                        if (ipdef->hosts[0].name == NULL) {
+                        if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) {
                             VIR_FREE(ipdef->hosts);
                             ipdef->nhosts = 0;
                             virReportOOMError();
@@ -8297,12 +8305,10 @@ static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
     int numActive = 0;
 
     if (nnames == 1) {
-        names[numActive] = strdup("default-pool");
-        if (names[numActive] == NULL) {
+        if (VIR_STRDUP(names[numActive], "default-pool") < 0)
             virReportOOMError();
-        } else {
+        else
             numActive++;
-        }
     }
     return numActive;
 }
@@ -8385,12 +8391,10 @@ static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names
 
                     if (nameUtf8) {
                         VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8);
-                        names[numActive] = strdup(nameUtf8);
-                        if (names[numActive] == NULL) {
+                        if (VIR_STRDUP(names[numActive], nameUtf8) < 0)
                             virReportOOMError();
-                        } else {
+                        else
                             numActive++;
-                        }
 
                         VBOX_UTF8_FREE(nameUtf8);
                     }
@@ -9007,12 +9011,10 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
             else
                 defOk = 0;
 
-            def.name = strdup(vol->name);
-            if (!(def.name && defOk))
+            if (VIR_STRDUP(def.name, vol->name) < 0)
                 defOk = 0;
 
-            def.key = strdup(vol->key);
-            if (!(def.key && defOk))
+            if (VIR_STRDUP(def.key, vol->key) < 0)
                 defOk = 0;
 
             rc = hardDisk->vtbl->GetFormat(hardDisk, &hddFormatUtf16);
@@ -9088,8 +9090,7 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
             VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
             if (hddLocationUtf8) {
 
-                ret = strdup(hddLocationUtf8);
-                if (!ret)
+                if (VIR_STRDUP(ret, hddLocationUtf8) < 0)
                     virReportOOMError();
 
                 VIR_DEBUG("Storage Volume Name: %s", vol->name);
@@ -9211,13 +9212,16 @@ vboxDomainScreenshot(virDomainPtr dom,
                     goto endjob;
                 }
 
+                if (VIR_STRDUP(ret, "image/png") < 0)
+                    goto endjob;
+
                 if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
                     virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                                    _("unable to open stream"));
+                    VIR_FREE(ret);
                     goto endjob;
                 }
 
-                ret = strdup("image/png");
 
 endjob:
                 VIR_FREE(screenData);
-- 
1.8.1.5


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