]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: netlink: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Thu, 9 Aug 2018 04:12:10 +0000 (09:42 +0530)
committerErik Skultety <eskultet@redhat.com>
Mon, 13 Aug 2018 18:03:53 +0000 (20:03 +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.

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

When a variable of type virNetlinkMsg * is declared using VIR_AUTOPTR,
the function nlmsg_free will be run automatically on it when it
goes out of scope.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virnetlink.c
src/util/virnetlink.h

index 162efe6f99598cf1b53075aab9976d6b86828533..ecf62c9e721a97d15f643eb5dcce6b44ac03d564 100644 (file)
@@ -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"
index 2a9de0a5757aba587aac20592680b766a77074f3..136b42b995ffaf63b1ec9e6e613abf3f446be7a7 100644 (file)
@@ -22,6 +22,7 @@
 
 # include "internal.h"
 # include "virmacaddr.h"
+# include "viralloc.h"
 
 # if defined(__linux__) && defined(HAVE_LIBNL)
 
@@ -44,6 +45,8 @@ struct nlmsghdr;
 
 # endif /* __linux__ */
 
+typedef struct nl_msg virNetlinkMsg;
+
 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(virNetlinkMsg, nlmsg_free)
+
 #endif /* __VIR_NETLINK_H__ */