From 8b36a2574f9129ae6bfe6785d66eaae8d28a7b1b Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 28 Feb 2022 15:21:31 +0100 Subject: [PATCH] lxc_fuse: Use automatic file closing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two functions (lxcProcHostRead() and lxcProcReadMeminfo()) that could benefit from automatic file closing. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/lxc/lxc_fuse.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 9eff188d5f..1dedbc4069 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -126,7 +126,7 @@ lxcProcHostRead(char *path, size_t size, off_t offset) { - int fd; + VIR_AUTOCLOSE fd = -1; int res; fd = open(path, O_RDONLY); @@ -136,7 +136,6 @@ lxcProcHostRead(char *path, if ((res = pread(fd, buf, size, offset)) < 0) res = -errno; - VIR_FORCE_CLOSE(fd); return res; } @@ -148,7 +147,7 @@ lxcProcReadMeminfo(char *hostpath, off_t offset) { int res; - FILE *fp = NULL; + g_autoptr(FILE) fp = NULL; g_autofree char *line = NULL; size_t n; struct virLXCMeminfo meminfo; @@ -251,7 +250,6 @@ lxcProcReadMeminfo(char *hostpath, memcpy(buf, virBufferCurrentContent(new_meminfo), res); cleanup: - VIR_FORCE_FCLOSE(fp); return res; }