[libvirt] [PATCH 06/13] src/phyp: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT

Michal Privoznik mprivozn at redhat.com
Fri Mar 7 09:46:02 UTC 2014


Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/phyp/phyp_driver.c | 16 +++++++---------
 src/phyp/phyp_driver.h |  2 +-
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 9adb6b0..e819256 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -570,19 +570,16 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id)
 {
     phyp_driverPtr phyp_driver = conn->privateData;
     uuid_tablePtr uuid_table = phyp_driver->uuid_table;
+    lparPtr item = NULL;
 
-    uuid_table->nlpars++;
-    size_t i = uuid_table->nlpars;
-    i--;
-
-    if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0)
+    if (VIR_ALLOC(item) < 0)
         goto err;
 
-    if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
-        goto err;
+    item->id = id;
+    memcpy(item->uuid, uuid, VIR_UUID_BUFLEN);
 
-    uuid_table->lpars[i]->id = id;
-    memcpy(uuid_table->lpars[i]->uuid, uuid, VIR_UUID_BUFLEN);
+    if (VIR_APPEND_ELEMENT_COPY(uuid_table->lpars, uuid_table->nlpars, item) < 0)
+        goto err;
 
     if (phypUUIDTable_WriteFile(conn) == -1)
         goto err;
@@ -593,6 +590,7 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id)
     return 0;
 
 err:
+    VIR_FREE(item);
     return -1;
 }
 
diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h
index ad05b15..a5e7369 100644
--- a/src/phyp/phyp_driver.h
+++ b/src/phyp/phyp_driver.h
@@ -56,7 +56,7 @@ struct _lpar {
 typedef struct _uuid_table uuid_table_t;
 typedef uuid_table_t *uuid_tablePtr;
 struct _uuid_table {
-    int nlpars;
+    size_t nlpars;
     lparPtr *lpars;
 };
 
-- 
1.9.0




More information about the libvir-list mailing list