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 <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Sukrit Bhatnagar 2018-07-28 23:31:20 +05:30 committed by Erik Skultety
parent d439eeb405
commit 7b706f33ac
2 changed files with 12 additions and 1 deletions

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

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