[libvirt] [PATCH v1 11/32] util: netdevip: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Sukrit Bhatnagar posted 32 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH v1 11/32] util: netdevip: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
Posted by Sukrit Bhatnagar 7 years, 6 months ago
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 variables of type virNetDevIPAddrPtr and virNetDevIPRoutePtr
are declared using VIR_AUTOPTR, the functions virNetDevIPAddrFree
and virNetDevIPRouteFree, respectively, will be run
automatically on them when they go out of scope.

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

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index bf98ed8..fdb0b74 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -27,7 +27,6 @@
 #include "virnetlink.h"
 #include "virfile.h"
 #include "virerror.h"
-#include "viralloc.h"
 #include "virlog.h"
 #include "virstring.h"
 #include "virutil.h"
@@ -1129,3 +1128,9 @@ virNetDevIPInfoAddToDev(const char *ifname,
  cleanup:
     return ret;
 }
+
+void
+virNetDevIPAddrFree(virNetDevIPAddrPtr ip)
+{
+    VIR_FREE(ip);
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 6b509ea..5608c37 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -84,6 +84,7 @@ int virNetDevIPAddrGet(const char *ifname, virSocketAddrPtr addr)
 int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
     ATTRIBUTE_NONNULL(1);
 bool virNetDevIPCheckIPv6Forwarding(void);
+void virNetDevIPAddrFree(virNetDevIPAddrPtr ip);
 
 /* virNetDevIPRoute object */
 void virNetDevIPRouteFree(virNetDevIPRoutePtr def);
@@ -97,4 +98,7 @@ void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
 int virNetDevIPInfoAddToDev(const char *ifname,
                             virNetDevIPInfo const *ipInfo);
 
+VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPAddr, virNetDevIPAddrFree)
+VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPRoute, virNetDevIPRouteFree)
+
 #endif /* __VIR_NETDEVIP_H__ */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 11/32] util: netdevip: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
Posted by Erik Skultety 7 years, 6 months ago
On Sat, Jul 28, 2018 at 11:31:26PM +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 variables of type virNetDevIPAddrPtr and virNetDevIPRoutePtr
> are declared using VIR_AUTOPTR, the functions virNetDevIPAddrFree
> and virNetDevIPRouteFree, respectively, will be run
> automatically on them when they go out of scope.
>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
> ---
>  src/util/virnetdevip.c | 7 ++++++-
>  src/util/virnetdevip.h | 4 ++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
> index bf98ed8..fdb0b74 100644
> --- a/src/util/virnetdevip.c
> +++ b/src/util/virnetdevip.c
> @@ -27,7 +27,6 @@
>  #include "virnetlink.h"
>  #include "virfile.h"
>  #include "virerror.h"
> -#include "viralloc.h"
>  #include "virlog.h"
>  #include "virstring.h"
>  #include "virutil.h"
> @@ -1129,3 +1128,9 @@ virNetDevIPInfoAddToDev(const char *ifname,
>   cleanup:
>      return ret;
>  }
> +
> +void
> +virNetDevIPAddrFree(virNetDevIPAddrPtr ip)
> +{
> +    VIR_FREE(ip);
> +}
> diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
> index 6b509ea..5608c37 100644
> --- a/src/util/virnetdevip.h
> +++ b/src/util/virnetdevip.h
> @@ -84,6 +84,7 @@ int virNetDevIPAddrGet(const char *ifname, virSocketAddrPtr addr)
>  int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
>      ATTRIBUTE_NONNULL(1);
>  bool virNetDevIPCheckIPv6Forwarding(void);
> +void virNetDevIPAddrFree(virNetDevIPAddrPtr ip);

These two hunks should be in a separate patch.

To the rest:
Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list