[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 03/35] util: netlink: 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.

This commit also typedefs virNlMsg to struct nl_msg type for use
with the cleanup macros.

When pointers to virNlMsg and virNetlinkHandle types are declared
using VIR_AUTOPTR, the functions nlmsg_free and virNetlinkFree,
respectively, will be run automatically on them when they go out
of scope.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr gmail com>
 src/util/virnetlink.c | 3 ++-
 src/util/virnetlink.h | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index fa1ba3e..1c1eac7 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -38,7 +38,6 @@
 #include "virnetlink.h"
 #include "virnetdev.h"
 #include "virlog.h"
-#include "viralloc.h"
 #include "virthread.h"
 #include "virmacaddr.h"
 #include "virerror.h"
@@ -72,6 +71,8 @@ typedef struct nl_handle virNetlinkHandle;
 typedef struct nl_sock virNetlinkHandle;
 # endif
+VIR_DEFINE_AUTOPTR_FUNC(virNetlinkHandle, virNetlinkFree)
 typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate;
 typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr;
 struct _virNetlinkEventSrvPrivate {
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
index 2a9de0a..647f589 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -44,6 +44,9 @@ struct nlmsghdr;
 # endif /* __linux__ */
+typedef struct nl_msg virNlMsg;
+typedef virNlMsg *virNlMsgPtr;
 int virNetlinkStartup(void);
 void virNetlinkShutdown(void);
@@ -123,4 +126,6 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
 int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr,
                                 unsigned int protocol);
+VIR_DEFINE_AUTOPTR_FUNC(virNlMsg, nlmsg_free)
 #endif /* __VIR_NETLINK_H__ */

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]