util: scsi: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

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>
This commit is contained in:
Sukrit Bhatnagar 2018-07-24 21:22:27 +05:30 committed by Erik Skultety
parent da5d031bd6
commit 30783d36b2
2 changed files with 6 additions and 2 deletions

View 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)

View 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__ */