提交 7b706f33 编写于 作者: S Sukrit Bhatnagar 提交者: Erik Skultety

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: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 d439eeb4
......@@ -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 {
......
......@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册