From db907a4d9cfb4a71069344e7c230b7efcedeea2a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 22 Apr 2020 16:19:21 +0200 Subject: [PATCH] qemuDomainSaveImageOpen: Automatically close 'fd' if unneeded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use VIR_AUTOCLOSE to declare it and remove all internal closing of the filedescriptor. This will allow getting rid of 'error' completely. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_driver.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 57c66c3401..c0ce1583b1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6691,7 +6691,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, bool open_write, bool unlink_corrupt) { - int fd = -1; + VIR_AUTOCLOSE fd = -1; int ret = -1; g_autoptr(virQEMUSaveData) data = NULL; virQEMUSaveHeaderPtr header; @@ -6723,7 +6723,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, header = &data->header; if (saferead(fd, header, sizeof(*header)) != sizeof(*header)) { if (unlink_corrupt) { - if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) { + if (unlink(path) < 0) { virReportSystemError(errno, _("cannot remove corrupt file: %s"), path); @@ -6744,7 +6744,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, sizeof(header->magic)) == 0) { msg = _("save image is incomplete"); if (unlink_corrupt) { - if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) { + if (unlink(path) < 0) { virReportSystemError(errno, _("cannot remove corrupt file: %s"), path); @@ -6812,10 +6812,12 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, *ret_def = g_steal_pointer(&def); *ret_data = g_steal_pointer(&data); - return fd; + ret = fd; + fd = -1; + + return ret; error: - VIR_FORCE_CLOSE(fd); return ret; } -- GitLab