From 7b706f33ac8bb4ff9ce2201ec7a9c1767a5dd51d Mon Sep 17 00:00:00 2001 From: Sukrit Bhatnagar Date: Sat, 28 Jul 2018 23:31:20 +0530 Subject: [PATCH] util: netdev: 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 virNetDevRxFilterPtr and virNetDevMcastEntryPtr are declared using VIR_AUTOPTR, the functions virNetDevRxFilterFree and virNetDevMcastEntryFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdev.c | 9 ++++++++- src/util/virnetdev.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 0777ecaf3f..9eca786c95 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -29,7 +29,6 @@ #include "virfile.h" #include "virerror.h" #include "vircommand.h" -#include "viralloc.h" #include "virpci.h" #include "virlog.h" #include "virstring.h" @@ -120,6 +119,14 @@ struct _virNetDevMcastEntry { virMacAddr macaddr; }; +static void +virNetDevMcastEntryFree(virNetDevMcastEntryPtr entry) +{ + VIR_FREE(entry); +} + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevMcastEntry, virNetDevMcastEntryFree) + typedef struct _virNetDevMcastList virNetDevMcastList; typedef virNetDevMcastList *virNetDevMcastListPtr; struct _virNetDevMcastList { diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 71eaf45e30..8860ea12f1 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -30,6 +30,7 @@ # include "virmacaddr.h" # include "virpci.h" # include "virnetdevvlan.h" +# include "viralloc.h" # ifdef HAVE_STRUCT_IFREQ typedef struct ifreq virIfreq; @@ -313,4 +314,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, int virNetDevRunEthernetScript(const char *ifname, const char *script) ATTRIBUTE_NOINLINE; + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevRxFilter, virNetDevRxFilterFree) + #endif /* __VIR_NETDEV_H__ */ -- 2.47.2