]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: kmod: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:39 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:21:25 +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/virkmod.c

index 219fad61dfb681dfe0ed1d6a4cbd92f436abd782..d981cd41380ba8d29cf1bfb4c9d47487cfdc472b 100644 (file)
@@ -155,13 +155,12 @@ virKModUnload(const char *module)
 bool
 virKModIsBlacklisted(const char *module)
 {
-    bool retval = false;
     size_t i;
-    char *drvblklst = NULL;
-    char *outbuf = NULL;
+    VIR_AUTOFREE(char *) drvblklst = NULL;
+    VIR_AUTOFREE(char *) outbuf = NULL;
 
     if (virAsprintfQuiet(&drvblklst, "blacklist %s\n", module) < 0)
-        goto cleanup;
+        return false;
 
     /* modprobe will convert all '-' into '_', so we need to as well */
     for (i = 0; i < drvblklst[i]; i++)
@@ -169,13 +168,10 @@ virKModIsBlacklisted(const char *module)
             drvblklst[i] = '_';
 
     if (doModprobe("-c", NULL, &outbuf, NULL) < 0)
-        goto cleanup;
+        return false;
 
     if (strstr(outbuf, drvblklst))
-        retval = true;
+        return true;
 
- cleanup:
-    VIR_FREE(drvblklst);
-    VIR_FREE(outbuf);
-    return retval;
+    return false;
 }