]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: scsi: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:27 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:21:19 +0000 (17:21 +0200)
Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
viralloc.h include, since that has moved from the source module into
the header.

When variables of type virSCSIDevicePtr and virUsedByInfoPtr
are declared using VIR_AUTOPTR, the functions virSCSIDeviceFree
and virSCSIDeviceUsedByInfoFree, respectively, will be run
automatically on them when they go out of scope.

This commit also adds an intermediate typedef for virUsedByInfo
type for use with the cleanup macros.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virscsi.c
src/util/virscsi.h

index b51103a86db0dc4a26b8c075a97e13e779b70871..33292f60e393798ac37b55a98a2a23e3b19e7d90 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "virlog.h"
 #include "virscsi.h"
-#include "viralloc.h"
 #include "virfile.h"
 #include "virutil.h"
 #include "virstring.h"
@@ -54,7 +53,8 @@ struct _virUsedByInfo {
     char *drvname; /* which driver */
     char *domname; /* which domain */
 };
-typedef struct _virUsedByInfo *virUsedByInfoPtr;
+typedef struct _virUsedByInfo virUsedByInfo;
+typedef virUsedByInfo *virUsedByInfoPtr;
 
 struct _virSCSIDevice {
     unsigned int adapter;
@@ -264,6 +264,7 @@ virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by)
     VIR_FREE(used_by->domname);
     VIR_FREE(used_by);
 }
+VIR_DEFINE_AUTOPTR_FUNC(virUsedByInfo, virSCSIDeviceUsedByInfoFree)
 
 void
 virSCSIDeviceFree(virSCSIDevicePtr dev)
index 9f8b3ecf1e6409f941b9d2ff07e8d318ee3f5c75..b96d8629b8fc20f578722dee7de799c16361ea90 100644 (file)
@@ -26,6 +26,7 @@
 
 # include "internal.h"
 # include "virobject.h"
+# include "viralloc.h"
 
 typedef struct _virSCSIDevice virSCSIDevice;
 typedef virSCSIDevice *virSCSIDevicePtr;
@@ -95,4 +96,6 @@ void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
 virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
                                        virSCSIDevicePtr dev);
 
+VIR_DEFINE_AUTOPTR_FUNC(virSCSIDevice, virSCSIDeviceFree)
+
 #endif /* __VIR_SCSI_H__ */