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 <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Michal Privoznik 2021-09-26 12:54:10 +02:00
parent f427e6c643
commit 1b2e06b1bf
3 changed files with 4 additions and 8 deletions

View File

@ -5539,7 +5539,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *name = NULL; const char *name = NULL;
char *file = NULL; char *file = NULL;
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL; g_autoptr(virshStream) st = NULL;
unsigned int screen = 0; unsigned int screen = 0;
unsigned int flags = 0; /* currently unused */ unsigned int flags = 0; /* currently unused */
@ -5610,7 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
unlink(file); unlink(file);
if (generated) if (generated)
VIR_FREE(file); VIR_FREE(file);
VIR_FORCE_CLOSE(fd);
VIR_FREE(mime); VIR_FREE(mime);
return ret; return ret;
} }

View File

@ -655,7 +655,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
const char *file = NULL; const char *file = NULL;
g_autoptr(virshStorageVol) vol = NULL; g_autoptr(virshStorageVol) vol = NULL;
bool ret = false; bool ret = false;
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL; g_autoptr(virshStream) st = NULL;
const char *name = NULL; const char *name = NULL;
unsigned long long offset = 0, length = 0; unsigned long long offset = 0, length = 0;
@ -731,7 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
return ret; return ret;
} }
@ -773,7 +772,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
const char *file = NULL; const char *file = NULL;
g_autoptr(virshStorageVol) vol = NULL; g_autoptr(virshStorageVol) vol = NULL;
bool ret = false; bool ret = false;
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL; g_autoptr(virshStream) st = NULL;
const char *name = NULL; const char *name = NULL;
unsigned long long offset = 0, length = 0; unsigned long long offset = 0, length = 0;
@ -846,7 +845,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
if (!ret && created) if (!ret && created)
unlink(file); unlink(file);
return ret; return ret;

View File

@ -2388,7 +2388,7 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
{ {
g_autofree char *ret = NULL; g_autofree char *ret = NULL;
const char *tmpdir; const char *tmpdir;
int fd; VIR_AUTOCLOSE fd = -1;
tmpdir = getenv("TMPDIR"); tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp"; if (!tmpdir) tmpdir = "/tmp";
@ -2403,7 +2403,6 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
if (safewrite(fd, doc, strlen(doc)) == -1) { if (safewrite(fd, doc, strlen(doc)) == -1) {
vshError(ctl, _("write: %s: failed to write to temporary file: %s"), vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
ret, g_strerror(errno)); ret, g_strerror(errno));
VIR_FORCE_CLOSE(fd);
unlink(ret); unlink(ret);
return NULL; return NULL;
} }