提交 8f03c6e8 编写于 作者: E Eric Blake

phyp: avoid memory leak on failure

* src/phyp/phyp_driver.c (phypUUIDTable_Init): Avoid memory leak
on error.
上级 ef6147c4
...@@ -807,31 +807,35 @@ phypUUIDTable_Pull(virConnectPtr conn) ...@@ -807,31 +807,35 @@ phypUUIDTable_Pull(virConnectPtr conn)
static int static int
phypUUIDTable_Init(virConnectPtr conn) phypUUIDTable_Init(virConnectPtr conn)
{ {
uuid_tablePtr uuid_table; uuid_tablePtr uuid_table = NULL;
phyp_driverPtr phyp_driver; phyp_driverPtr phyp_driver;
int nids_numdomains = 0; int nids_numdomains = 0;
int nids_listdomains = 0; int nids_listdomains = 0;
int *ids = NULL; int *ids = NULL;
unsigned int i = 0; unsigned int i = 0;
int ret = -1;
bool table_created = false;
if ((nids_numdomains = phypNumDomainsGeneric(conn, 2)) < 0) if ((nids_numdomains = phypNumDomainsGeneric(conn, 2)) < 0)
goto err; goto cleanup;
if (VIR_ALLOC_N(ids, nids_numdomains) < 0) { if (VIR_ALLOC_N(ids, nids_numdomains) < 0) {
virReportOOMError(); virReportOOMError();
goto err; goto cleanup;
} }
if ((nids_listdomains = if ((nids_listdomains =
phypListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0) phypListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0)
goto err; goto cleanup;
/* exit early if there are no domains */ /* exit early if there are no domains */
if (nids_numdomains == 0 && nids_listdomains == 0) if (nids_numdomains == 0 && nids_listdomains == 0) {
goto exit; ret = 0;
else if (nids_numdomains != nids_listdomains) { goto cleanup;
}
if (nids_numdomains != nids_listdomains) {
VIR_ERROR0(_("Unable to determine number of domains.")); VIR_ERROR0(_("Unable to determine number of domains."));
goto err; goto cleanup;
} }
phyp_driver = conn->privateData; phyp_driver = conn->privateData;
...@@ -841,11 +845,12 @@ phypUUIDTable_Init(virConnectPtr conn) ...@@ -841,11 +845,12 @@ phypUUIDTable_Init(virConnectPtr conn)
/* try to get the table from server */ /* try to get the table from server */
if (phypUUIDTable_Pull(conn) == -1) { if (phypUUIDTable_Pull(conn) == -1) {
/* file not found in the server, creating a new one */ /* file not found in the server, creating a new one */
table_created = true;
if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) { if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) {
for (i = 0; i < uuid_table->nlpars; i++) { for (i = 0; i < uuid_table->nlpars; i++) {
if (VIR_ALLOC(uuid_table->lpars[i]) < 0) { if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
virReportOOMError(); virReportOOMError();
goto err; goto cleanup;
} }
uuid_table->lpars[i]->id = ids[i]; uuid_table->lpars[i]->id = ids[i];
...@@ -855,27 +860,30 @@ phypUUIDTable_Init(virConnectPtr conn) ...@@ -855,27 +860,30 @@ phypUUIDTable_Init(virConnectPtr conn)
} }
} else { } else {
virReportOOMError(); virReportOOMError();
goto err; goto cleanup;
} }
if (phypUUIDTable_WriteFile(conn) == -1) if (phypUUIDTable_WriteFile(conn) == -1)
goto err; goto cleanup;
if (phypUUIDTable_Push(conn) == -1) if (phypUUIDTable_Push(conn) == -1)
goto err; goto cleanup;
} else { } else {
if (phypUUIDTable_ReadFile(conn) == -1) if (phypUUIDTable_ReadFile(conn) == -1)
goto err; goto cleanup;
goto exit;
} }
exit: ret = 0;
VIR_FREE(ids);
return 0;
err: cleanup:
if (ret < 0 && table_created) {
for (i = 0; i < uuid_table->nlpars; i++) {
VIR_FREE(uuid_table->lpars[i]);
}
VIR_FREE(uuid_table->lpars);
}
VIR_FREE(ids); VIR_FREE(ids);
return -1; return ret;
} }
static void static void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册