[libvirt] [PATCH v1 04/32] util: macaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Erik Skultety eskultet at redhat.com
Fri Aug 3 07:30:22 UTC 2018


On Sat, Jul 28, 2018 at 11:31:19PM +0530, Sukrit Bhatnagar wrote:
> 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 at gmail.com>
> ---
>  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);
> +}

I understand the reason behind this change, however, I don't feel like this
will bring any benefits only because we said that VIR_AUTOFREE should be used
with scalar types only, I'd prefer simply using VIR_AUTOFREE here, CC'ng Pavel
to share his opinion.

Erik




More information about the libvir-list mailing list