From: Michal Privoznik Date: Fri, 7 Mar 2014 08:33:31 +0000 (+0100) Subject: src/phyp: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT X-Git-Tag: v1.2.3-rc1~323 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f8b040d9aa8a8a53c59fe37c83178c0114d8bd0;p=thirdparty%2Flibvirt.git src/phyp: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT Signed-off-by: Michal Privoznik --- diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 9adb6b05fe..e819256699 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 ad05b15daf..a5e7369369 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; };