[libvirt] [PATCH v3 29/35] util: iohelper: use VIR_AUTOFREE instead of VIR_FREE for scalar types

Sukrit Bhatnagar skrtbhtngr at gmail.com
Sat Jun 30 09:00:33 UTC 2018


By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr at gmail.com>
---
 src/util/iohelper.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index bb8a8dd..f7794dc 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -46,7 +46,7 @@
 static int
 runIO(const char *path, int fd, int oflags)
 {
-    void *base = NULL; /* Location to be freed */
+    VIR_AUTOFREE(void *) base = NULL; /* Location to be freed */
     char *buf = NULL; /* Aligned location within base */
     size_t buflen = 1024*1024;
     intptr_t alignMask = 64*1024 - 1;
@@ -174,8 +174,6 @@ runIO(const char *path, int fd, int oflags)
         virReportSystemError(errno, _("Unable to close %s"), path);
         ret = -1;
     }
-
-    VIR_FREE(base);
     return ret;
 }
 
-- 
1.8.3.1




More information about the libvir-list mailing list