]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: hook: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:18 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:21:10 +0000 (17:21 +0200)
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@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virhook.c

index facd74aeff5f6c7ad93c1706b3847bdb5289c6f8..4673655dee22e470d812a1ac8e5d512d53b1f359 100644 (file)
@@ -122,8 +122,7 @@ static int virHooksFound = -1;
 static int
 virHookCheck(int no, const char *driver)
 {
-    char *path;
-    int ret;
+    VIR_AUTOFREE(char *) path = NULL;
 
     if (driver == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -139,18 +138,17 @@ virHookCheck(int no, const char *driver)
     }
 
     if (!virFileExists(path)) {
-        ret = 0;
         VIR_DEBUG("No hook script %s", path);
-    } else if (!virFileIsExecutable(path)) {
-        ret = 0;
+        return 0;
+    }
+
+    if (!virFileIsExecutable(path)) {
         VIR_WARN("Non-executable hook script %s", path);
-    } else {
-        ret = 1;
-        VIR_DEBUG("Found hook script %s", path);
+        return 0;
     }
 
-    VIR_FREE(path);
-    return ret;
+    VIR_DEBUG("Found hook script %s", path);
+    return 1;
 }
 
 /*
@@ -233,7 +231,7 @@ virHookCall(int driver,
             char **output)
 {
     int ret;
-    char *path;
+    VIR_AUTOFREE(char *) path = NULL;
     virCommandPtr cmd;
     const char *drvstr;
     const char *opstr;
@@ -318,7 +316,5 @@ virHookCall(int driver,
 
     virCommandFree(cmd);
 
-    VIR_FREE(path);
-
     return ret;
 }