]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: netdev: Define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Sat, 28 Jul 2018 18:01:20 +0000 (23:31 +0530)
committerErik Skultety <eskultet@redhat.com>
Tue, 7 Aug 2018 14:29:55 +0000 (16:29 +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 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 <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virnetdev.c
src/util/virnetdev.h

index 0777ecaf3f4cf2c6f35383b1bb30a0c58f494665..9eca786c95da4284ecde5e4d21fb809b56276119 100644 (file)
@@ -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 {
index 71eaf45e30566e8baf877bdc7f90b85f6414509b..8860ea12f177bc8a8c3976d80817e9623e4479c2 100644 (file)
@@ -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__ */