[libvirt] [PATCH v2 19/35] util: netdevmacvlan: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Sukrit Bhatnagar skrtbhtngr at gmail.com
Sun Aug 5 20:43:46 UTC 2018


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 a variable of type virNetlinkCallbackDataPtr is declared using
VIR_AUTOPTR, the function virNetlinkCallbackDataFree will be run
automatically on it when it goes out of scope.

This commit also adds an intermediate typedef for virNetlinkCallbackData
type for use with the cleanup macros.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr at gmail.com>
---
 src/util/virnetdevmacvlan.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index fb41bf9..91c6244 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -576,7 +576,7 @@ static const uint32_t modeMap[VIR_NETDEV_MACVLAN_MODE_LAST] = {
 };
 
 /* Struct to hold the state and configuration of a 802.1qbg port */
-struct virNetlinkCallbackData {
+struct _virNetlinkCallbackData {
     char *cr_ifname;
     virNetDevVPortProfilePtr virtPortProfile;
     virMacAddr macaddress;
@@ -587,7 +587,8 @@ struct virNetlinkCallbackData {
     unsigned int linkState;
 };
 
-typedef struct virNetlinkCallbackData *virNetlinkCallbackDataPtr;
+typedef struct _virNetlinkCallbackData virNetlinkCallbackData;
+typedef virNetlinkCallbackData *virNetlinkCallbackDataPtr;
 
 # define INSTANCE_STRLEN 36
 
@@ -870,6 +871,8 @@ virNetlinkCallbackDataFree(virNetlinkCallbackDataPtr calld)
     VIR_FREE(calld);
 }
 
+VIR_DEFINE_AUTOPTR_FUNC(virNetlinkCallbackData, virNetlinkCallbackDataFree)
+
 /**
  * virNetDevMacVLanVPortProfileDestroyCallback:
  *
-- 
1.8.3.1




More information about the libvir-list mailing list