By making use of GNU C's cleanup attribute handled by the VIR_AUTOCLOSE macro, many of the VIR_FORCE_CLOSE calls can be dropped, which in turn leads to getting rid of many of our cleanup sections. Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/phyp/phyp_driver.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 28a1fa3..c813fac 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -463,37 +463,33 @@ phypUUIDTable_WriteFile(virConnectPtr conn) phyp_driverPtr phyp_driver = conn->privateData; uuid_tablePtr uuid_table = phyp_driver->uuid_table; size_t i = 0; - int fd = -1; char local_file[] = "./uuid_table"; + VIR_AUTOCLOSE(fd); if ((fd = creat(local_file, 0755)) == -1) - goto err; + return -1; for (i = 0; i < uuid_table->nlpars; i++) { if (safewrite(fd, &uuid_table->lpars[i]->id, sizeof(uuid_table->lpars[i]->id)) != sizeof(uuid_table->lpars[i]->id)) { VIR_ERROR(_("Unable to write information to local file.")); - goto err; + return -1; } if (safewrite(fd, uuid_table->lpars[i]->uuid, VIR_UUID_BUFLEN) != VIR_UUID_BUFLEN) { VIR_ERROR(_("Unable to write information to local file.")); - goto err; + return -1; } } if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("Could not close %s"), local_file); - goto err; + return -1; } return 0; - - err: - VIR_FORCE_CLOSE(fd); - return -1; } static int @@ -641,14 +637,14 @@ phypUUIDTable_ReadFile(virConnectPtr conn) phyp_driverPtr phyp_driver = conn->privateData; uuid_tablePtr uuid_table = phyp_driver->uuid_table; size_t i = 0; - int fd = -1; char local_file[] = "./uuid_table"; int rc = 0; int id; + VIR_AUTOCLOSE(fd); if ((fd = open(local_file, O_RDONLY)) == -1) { VIR_WARN("Unable to read information from local file."); - goto err; + return -1; } /* Creating a new data base and writing to local file */ @@ -658,28 +654,23 @@ phypUUIDTable_ReadFile(virConnectPtr conn) rc = read(fd, &id, sizeof(int)); if (rc == sizeof(int)) { if (VIR_ALLOC(uuid_table->lpars[i]) < 0) - goto err; + return -1; uuid_table->lpars[i]->id = id; } else { VIR_WARN ("Unable to read from information from local file."); - goto err; + return -1; } rc = read(fd, uuid_table->lpars[i]->uuid, VIR_UUID_BUFLEN); if (rc != VIR_UUID_BUFLEN) { VIR_WARN("Unable to read information from local file."); - goto err; + return -1; } } } - VIR_FORCE_CLOSE(fd); return 0; - - err: - VIR_FORCE_CLOSE(fd); - return -1; } static int -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list