]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: socketaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Sat, 28 Jul 2018 18:01:23 +0000 (23:31 +0530)
committerErik Skultety <eskultet@redhat.com>
Tue, 7 Aug 2018 14:29:55 +0000 (16:29 +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.

When a variable of type virSocketAddrPtr is declared using
VIR_AUTOPTR, the function virSocketAddrFree 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/virsocketaddr.c
src/util/virsocketaddr.h

index 80f75fb9cd34859c59fee6b481248877a22ca516..6b52a3d58cfa8bafebd0bb37a85a587e13fde295 100644 (file)
@@ -26,7 +26,6 @@
 #include "virsocketaddr.h"
 #include "virerror.h"
 #include "virstring.h"
-#include "viralloc.h"
 #include "virbuffer.h"
 
 #include <netdb.h>
index 06cfd33d72f28fd572653332e56666a8d82339f7..66f599869c827303d6d970a7afa74087ee0aa53d 100644 (file)
 #ifndef __VIR_SOCKETADDR_H__
 # define __VIR_SOCKETADDR_H__
 
-# include "internal.h"
-
 # include <netinet/in.h>
 # include <sys/socket.h>
 # ifdef HAVE_SYS_UN_H
 #  include <sys/un.h>
 # endif
 
+# include "internal.h"
+# include "viralloc.h"
+
 /* On architectures which lack these limits, define them (ie. Cygwin).
  * Note that the libvirt code should be robust enough to handle the
  * case where actual value is longer than these limits (eg. by setting
@@ -164,4 +165,6 @@ int virSocketAddrPTRDomain(const virSocketAddr *addr,
 
 void virSocketAddrFree(virSocketAddrPtr addr);
 
+VIR_DEFINE_AUTOPTR_FUNC(virSocketAddr, virSocketAddrFree)
+
 #endif /* __VIR_SOCKETADDR_H__ */