[PATCH v2 30/37] Adapt to VIR_STRDUP in src/xen/*

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

 



---
 src/xen/xen_driver.c     |  2 +-
 src/xen/xen_hypervisor.c | 15 +++++---------
 src/xen/xen_inotify.c    | 11 ++++------
 src/xen/xend_internal.c  | 53 +++++++++++++++---------------------------------
 src/xen/xm_internal.c    |  6 +++---
 src/xen/xs_internal.c    | 22 ++++++++------------
 6 files changed, 37 insertions(+), 72 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 526786b..25d5394 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2504,7 +2504,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
 
     if (VIR_ALLOC(info) < 0)
         goto memory_error;
-    if (!(info->name = strdup(name)))
+    if (VIR_STRDUP(info->name, name) < 0)
         goto memory_error;
 
     memcpy(info->uuid, uuid, VIR_UUID_BUFLEN);
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index e15f7f2..c5f6c0f 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -1199,15 +1199,13 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams)
 
         switch (op.u.getschedulerid.sched_id){
             case XEN_SCHEDULER_SEDF:
-                schedulertype = strdup("sedf");
-                if (schedulertype == NULL)
+                if (VIR_STRDUP(schedulertype, "sedf") < 0)
                     virReportOOMError();
                 if (nparams)
                     *nparams = XEN_SCHED_SEDF_NPARAM;
                 break;
             case XEN_SCHEDULER_CREDIT:
-                schedulertype = strdup("credit");
-                if (schedulertype == NULL)
+                if (VIR_STRDUP(schedulertype, "credit") < 0)
                     virReportOOMError();
                 if (nparams)
                     *nparams = XEN_SCHED_CRED_NPARAM;
@@ -2894,12 +2892,9 @@ xenHypervisorDomainGetOSType(virDomainPtr dom)
         return NULL;
     }
 
-    if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM)
-        ostype = strdup("hvm");
-    else
-        ostype = strdup("linux");
-
-    if (ostype == NULL)
+    if (VIR_STRDUP(ostype,
+                   XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM ?
+                   "hvm" : "linux") < 0)
         virReportOOMError();
 
     return ostype;
diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index d83708c..3d0d094 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -39,7 +39,7 @@
 #include "virlog.h"
 #include "viruuid.h"
 #include "virfile.h"
-
+#include "virstring.h"
 #include "xm_internal.h" /* for xenXMDomainConfigParse */
 
 #define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
@@ -62,10 +62,8 @@ xenInotifyXenCacheLookup(virConnectPtr conn,
         return -1;
     }
 
-    *name = strdup(entry->def->name);
     memcpy(uuid, entry->def->uuid, VIR_UUID_BUFLEN);
-
-    if (!*name) {
+    if (VIR_STRDUP(*name, entry->def->name) < 0) {
         VIR_DEBUG("Error getting dom from def");
         virReportOOMError();
         return -1;
@@ -107,8 +105,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
            list info */
         for (i = 0 ; i < priv->configInfoList->count ; i++) {
             if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
-                *name = strdup(priv->configInfoList->doms[i]->name);
-                if (!*name) {
+                if (VIR_STRDUP(*name, priv->configInfoList->doms[i]->name) < 0) {
                     virReportOOMError();
                     return -1;
                 }
@@ -122,7 +119,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
         return -1;
     }
 
-    if (!(*name = strdup(dom->name))) {
+    if (VIR_STRDUP(*name, dom->name) < 0) {
         virReportOOMError();
         virDomainFree(dom);
         return -1;
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 97f44ab..4081050 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -761,8 +761,7 @@ xenDaemonListDomainsOld(virConnectPtr xend)
          _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
         if (node->kind != SEXPR_VALUE)
             continue;
-        ret[i] = strdup(node->u.value);
-        if (!ret[i])
+        if (VIR_STRDUP(ret[i], node->u.value) < 0)
             goto no_memory;
         i++;
     }
@@ -887,12 +886,9 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
                      "%s", _("domain information incomplete, missing name"));
       goto error;
     }
-    if (domname) {
-      *domname = strdup(name);
-      if (*domname == NULL) {
-          virReportOOMError();
-          goto error;
-      }
+    if (domname && VIR_STRDUP(*domname, name) < 0) {
+        virReportOOMError();
+        goto error;
     }
 
     if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
@@ -1454,13 +1450,7 @@ xenDaemonDomainGetOSType(virDomainPtr domain)
     if (root == NULL)
         return NULL;
 
-    if (sexpr_lookup(root, "domain/image/hvm")) {
-        type = strdup("hvm");
-    } else {
-        type = strdup("linux");
-    }
-
-    if (type == NULL)
+    if (VIR_STRDUP(type, sexpr_lookup(root, "domain/image/hvm") ? "hvm" : "linux") < 0)
         virReportOOMError();
 
     sexpr_free(root);
@@ -2363,12 +2353,8 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
         else
             id = -1;
 
-        if (domname) {
-            name = strdup(domname);
-
-            if (name == NULL)
-                virReportOOMError();
-        }
+        if (domname && VIR_STRDUP(name, domname) < 0)
+            virReportOOMError();
 
         sexpr_free(root);
     }
@@ -2533,7 +2519,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
             goto cleanup;
 
         if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
-            if (!(target = strdup(dev->data.disk->dst))) {
+            if (VIR_STRDUP(target, dev->data.disk->dst) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -2551,7 +2537,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
         char macStr[VIR_MAC_STRING_BUFLEN];
         virMacAddrFormat(&dev->data.net->mac, macStr);
 
-        if (!(target = strdup(macStr))) {
+        if (VIR_STRDUP(target, macStr) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -2886,9 +2872,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart)
 
         /* Change the autostart value in place, then define the new sexpr */
         VIR_FREE(autonode->u.s.car->u.value);
-        autonode->u.s.car->u.value = (autostart ? strdup("start")
-                                                : strdup("ignore"));
-        if (!(autonode->u.s.car->u.value)) {
+        if (VIR_STRDUP(autonode->u.s.car->u.value,autostart ? "start" : "ignore") < 0) {
             virReportOOMError();
             goto error;
         }
@@ -3050,8 +3034,7 @@ xenDaemonDomainMigratePerform(virDomainPtr domain,
             virURIFree(uriptr);
             return -1;
         }
-        hostname = strdup(uriptr->server);
-        if (!hostname) {
+        if (VIR_STRDUP(hostname, uriptr->server) < 0) {
             virReportOOMError();
             virURIFree(uriptr);
             return -1;
@@ -3072,16 +3055,14 @@ xenDaemonDomainMigratePerform(virDomainPtr domain,
 
         /* Get the hostname. */
         n = p - uri; /* n = Length of hostname in bytes. */
-        hostname = strdup(uri);
-        if (!hostname) {
+        if (VIR_STRDUP(hostname, uri) < 0) {
             virReportOOMError();
             return -1;
         }
         hostname[n] = '\0';
     }
     else {                      /* "hostname" (or IP address) */
-        hostname = strdup(uri);
-        if (!hostname) {
+        if (VIR_STRDUP(hostname, uri) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -3263,7 +3244,7 @@ xenDaemonListDefinedDomains(virConnectPtr conn,
         if (node->kind != SEXPR_VALUE)
             continue;
 
-        if ((names[ret++] = strdup(node->u.value)) == NULL) {
+        if (VIR_STRDUP(names[ret++], node->u.value) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -3322,16 +3303,14 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
         goto error;
     }
     if (STREQ(ret, "credit")) {
-        schedulertype = strdup("credit");
-        if (schedulertype == NULL){
+        if (VIR_STRDUP(schedulertype, "credit") < 0) {
             virReportOOMError();
             goto error;
         }
         if (nparams)
             *nparams = XEN_SCHED_CRED_NPARAM;
     } else if (STREQ(ret, "sedf")) {
-        schedulertype = strdup("sedf");
-        if (schedulertype == NULL){
+        if (VIR_STRDUP(schedulertype, "sedf") < 0) {
             virReportOOMError();
             goto error;
         }
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 921c66a..1a74133 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -260,7 +260,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
             virReportOOMError();
             return -1;
         }
-        if ((entry->filename = strdup(filename)) == NULL) {
+        if (VIR_STRDUP(entry->filename, filename) < 0) {
             virReportOOMError();
             VIR_FREE(entry);
             return -1;
@@ -1092,7 +1092,7 @@ xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
         goto error;
     }
 
-    if ((entry->filename = strdup(filename)) == NULL) {
+    if (VIR_STRDUP(entry->filename, filename) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -1190,7 +1190,7 @@ xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const void *name, void *data)
 
     dom = xenDaemonLookupByName(ctx->conn, name);
     if (!dom) {
-        if (!(ctx->names[ctx->count] = strdup(name)))
+        if (VIR_STRDUP(ctx->names[ctx->count], name) < 0)
             ctx->oom = 1;
         else
             ctx->count++;
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index 5f0df63..304b7c5 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -50,6 +50,7 @@
 #include "xen_driver.h"
 #include "xs_internal.h"
 #include "xen_hypervisor.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_XEN
 
@@ -851,9 +852,7 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac)
         VIR_FREE(val);
 
         if (match) {
-            ret = strdup(list[i]);
-
-            if (ret == NULL)
+            if (VIR_STRDUP(ret, list[i]) < 0)
                 virReportOOMError();
 
             break;
@@ -904,9 +903,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
             if ((devlen != len) || memcmp(val, dev, len)) {
                 VIR_FREE(val);
             } else {
-                ret = strdup(list[i]);
-
-                if (ret == NULL)
+                if (VIR_STRDUP(ret, list[i]) < 0)
                     virReportOOMError();
 
                 VIR_FREE(val);
@@ -927,9 +924,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
             if ((devlen != len) || memcmp(val, dev, len)) {
                 VIR_FREE(val);
             } else {
-                ret = strdup(list[i]);
-
-                if (ret == NULL)
+                if (VIR_STRDUP(ret, list[i]) < 0)
                     virReportOOMError();
 
                 VIR_FREE(val);
@@ -982,7 +977,8 @@ xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
         VIR_FREE(val);
 
         if (match) {
-            ret = strdup(list[i]);
+            if (VIR_STRDUP(ret, list[i]) < 0)
+                virReportOOMError();
             break;
         }
     }
@@ -1091,14 +1087,12 @@ xenStoreAddWatch(virConnectPtr conn,
     if (VIR_ALLOC(watch) < 0)
         goto no_memory;
 
-    watch->path   = strdup(path);
-    watch->token  = strdup(token);
     watch->cb     = cb;
     watch->opaque = opaque;
 
-    if (watch->path == NULL || watch->token == NULL) {
+    if (VIR_STRDUP(watch->path, path) < 0 ||
+        VIR_STRDUP(watch->token, token) < 0)
         goto no_memory;
-    }
 
     /* Make space on list */
     n = list->count;
-- 
1.8.1.5

--
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]