[libvirt] [PATCH v2 17/37] Adapt to VIR_STRDUP in src/phyp/*

Michal Privoznik mprivozn at redhat.com
Mon Apr 29 13:50:39 UTC 2013


---
 src/phyp/phyp_driver.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 85eb650..1cb92d2 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -954,9 +954,7 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
     }
 
     if (conn->uri->user != NULL) {
-        username = strdup(conn->uri->user);
-
-        if (username == NULL) {
+        if (VIR_STRDUP(username, conn->uri->user) < 0) {
             virReportOOMError();
             goto err;
         }
@@ -1141,12 +1139,10 @@ phypConnectOpen(virConnectPtr conn,
 
     if (conn->uri->path) {
         /* need to shift one byte in order to remove the first "/" of URI component */
-        if (conn->uri->path[0] == '/')
-            managed_system = strdup(conn->uri->path + 1);
-        else
-            managed_system = strdup(conn->uri->path);
-
-        if (!managed_system) {
+        if ((conn->uri->path[0] == '/' &&
+             VIR_STRDUP(managed_system, conn->uri->path + 1) < 0) ||
+            (conn->uri->path[0] != '/' &&
+             VIR_STRDUP(managed_system, conn->uri->path) < 0)) {
             virReportOOMError();
             goto failure;
         }
@@ -1498,9 +1494,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
         else
             goto cleanup;
 
-        backing_device = strdup(char_ptr);
-
-        if (backing_device == NULL) {
+        if (VIR_STRDUP(backing_device, char_ptr) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1731,9 +1725,7 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml)
         goto cleanup;
     }
 
-    def->os.type = strdup("aix");
-
-    if (def->os.type == NULL) {
+    if (VIR_STRDUP(def->os.type, "aix") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -2281,9 +2273,7 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
         goto cleanup;
     }
 
-    voldef.key = strdup(vol->key);
-
-    if (voldef.key == NULL) {
+    if (VIR_STRDUP(voldef.key, vol->key) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -2399,7 +2389,7 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes,
 
             if (char_ptr) {
                 *char_ptr = '\0';
-                if ((volumes[got++] = strdup(volumes_list)) == NULL) {
+                if (VIR_STRDUP(volumes[got++], volumes_list) < 0) {
                     virReportOOMError();
                     goto cleanup;
                 }
@@ -2600,7 +2590,7 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools)
 
             if (char_ptr) {
                 *char_ptr = '\0';
-                if ((pools[got++] = strdup(storage_pools)) == NULL) {
+                if (VIR_STRDUP(pools[got++], storage_pools) < 0) {
                     virReportOOMError();
                     goto cleanup;
                 }
@@ -3067,7 +3057,7 @@ phypConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
 
         if (char_ptr) {
             *char_ptr = '\0';
-            if ((names[got++] = strdup(networks)) == NULL) {
+            if (VIR_STRDUP(names[got++], networks) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -3234,7 +3224,7 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames
 
             if (char_ptr) {
                 *char_ptr = '\0';
-                if ((names[got++] = strdup(domains)) == NULL) {
+                if (VIR_STRDUP(names[got++], domains) < 0) {
                     virReportOOMError();
                     goto cleanup;
                 }
-- 
1.8.1.5




More information about the libvir-list mailing list