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 virMacAddrPtr is declared using VIR_AUTOPTR, the function virMacAddrFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx> --- src/util/virmacaddr.c | 6 ++++++ src/util/virmacaddr.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 7afe032..e739775 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -252,3 +252,9 @@ virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]) { return memcmp(virMacAddrBroadcastAddrRaw, s, sizeof(*s)) == 0; } + +void +virMacAddrFree(virMacAddrPtr addr) +{ + VIR_FREE(addr); +} diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index d0dd4a4..39dd51b 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -25,6 +25,7 @@ # define __VIR_MACADDR_H__ # include "internal.h" +# include "viralloc.h" # define VIR_MAC_BUFLEN 6 # define VIR_MAC_HEXLEN (VIR_MAC_BUFLEN * 2) @@ -64,5 +65,8 @@ int virMacAddrParseHex(const char* str, bool virMacAddrIsUnicast(const virMacAddr *addr); bool virMacAddrIsMulticast(const virMacAddr *addr); bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]); +void virMacAddrFree(virMacAddrPtr addr); + +VIR_DEFINE_AUTOPTR_FUNC(virMacAddr, virMacAddrFree) #endif /* __VIR_MACADDR_H__ */ -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list