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

index 33292f60e393798ac37b55a98a2a23e3b19e7d90..ba0a688ad6eee9091f2269e61db46823ef56ba5c 100644 (file)
@@ -115,7 +115,7 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
 {
     DIR *dir = NULL;
     struct dirent *entry;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     char *sg = NULL;
     unsigned int adapter_id;
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
@@ -139,7 +139,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
 
  cleanup:
     VIR_DIR_CLOSE(dir);
-    VIR_FREE(path);
     return sg;
 }
 
@@ -155,7 +154,7 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
 {
     DIR *dir = NULL;
     struct dirent *entry;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     char *name = NULL;
     unsigned int adapter_id;
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
@@ -178,7 +177,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
 
  cleanup:
     VIR_DIR_CLOSE(dir);
-    VIR_FREE(path);
     return name;
 }
 
@@ -192,11 +190,11 @@ virSCSIDeviceNew(const char *sysfs_prefix,
                  bool shareable)
 {
     virSCSIDevicePtr dev, ret = NULL;
-    char *sg = NULL;
-    char *vendor_path = NULL;
-    char *model_path = NULL;
-    char *vendor = NULL;
-    char *model = NULL;
+    VIR_AUTOFREE(char *) sg = NULL;
+    VIR_AUTOFREE(char *) vendor_path = NULL;
+    VIR_AUTOFREE(char *) model_path = NULL;
+    VIR_AUTOFREE(char *) vendor = NULL;
+    VIR_AUTOFREE(char *) model = NULL;
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
 
     if (VIR_ALLOC(dev) < 0)
@@ -247,11 +245,6 @@ virSCSIDeviceNew(const char *sysfs_prefix,
 
     ret = dev;
  cleanup:
-    VIR_FREE(sg);
-    VIR_FREE(vendor);
-    VIR_FREE(model);
-    VIR_FREE(vendor_path);
-    VIR_FREE(model_path);
     if (!ret)
         virSCSIDeviceFree(dev);
     return ret;