From 1b2e06b1bff04e74d64db38c40e8179d0673ccf9 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Sun, 26 Sep 2021 12:54:10 +0200 Subject: [PATCH] virsh: Use VIR_AUTOCLOSE more There are few places where we can replace explicit VIR_FORCE_CLOSE() with VIR_AUTOCLOSE annotation. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- tools/virsh-domain.c | 3 +-- tools/virsh-volume.c | 6 ++---- tools/vsh.c | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index db3f1b41c1..dbddefb4a5 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5539,7 +5539,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *name = NULL; char *file = NULL; - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autoptr(virshStream) st = NULL; unsigned int screen = 0; unsigned int flags = 0; /* currently unused */ @@ -5610,7 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - VIR_FORCE_CLOSE(fd); VIR_FREE(mime); return ret; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 70b6eac687..4c8e841701 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -655,7 +655,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) const char *file = NULL; g_autoptr(virshStorageVol) vol = NULL; bool ret = false; - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autoptr(virshStream) st = NULL; const char *name = NULL; unsigned long long offset = 0, length = 0; @@ -731,7 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FORCE_CLOSE(fd); return ret; } @@ -773,7 +772,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) const char *file = NULL; g_autoptr(virshStorageVol) vol = NULL; bool ret = false; - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autoptr(virshStream) st = NULL; const char *name = NULL; unsigned long long offset = 0, length = 0; @@ -846,7 +845,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FORCE_CLOSE(fd); if (!ret && created) unlink(file); return ret; diff --git a/tools/vsh.c b/tools/vsh.c index 7b77acad34..ecb591fb63 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2388,7 +2388,7 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc) { g_autofree char *ret = NULL; const char *tmpdir; - int fd; + VIR_AUTOCLOSE fd = -1; tmpdir = getenv("TMPDIR"); if (!tmpdir) tmpdir = "/tmp"; @@ -2403,7 +2403,6 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc) if (safewrite(fd, doc, strlen(doc)) == -1) { vshError(ctl, _("write: %s: failed to write to temporary file: %s"), ret, g_strerror(errno)); - VIR_FORCE_CLOSE(fd); unlink(ret); return NULL; }