Re: [libvirt] [PATCH v1 09/32] util: socketaddr: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-08-03 Thread Erik Skultety
On Sat, Jul 28, 2018 at 11:31:24PM +0530, Sukrit Bhatnagar wrote:
> By making use of GNU C's cleanup attribute handled by the
> VIR_AUTOFREE macro for declaring scalar variables, majority
> of the VIR_FREE calls can be dropped, which in turn leads to
> getting rid of most of our cleanup sections.
>
> Signed-off-by: Sukrit Bhatnagar 
> ---
Reviewed-by: Erik Skultety 

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


[libvirt] [PATCH v1 09/32] util: socketaddr: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-07-28 Thread Sukrit Bhatnagar
By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar 
---
 src/util/virsocketaddr.c | 70 
 1 file changed, 29 insertions(+), 41 deletions(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 6b52a3d..eee725d 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -432,10 +432,10 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
 if (withService) {
 if (virAsprintf(, VIR_LOOPBACK_IPV4_ADDR"%s0",
 separator ? separator : ":") < 0)
-goto error;
+return NULL;
 } else {
 if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0)
-goto error;
+return NULL;
 }
 return addrstr;
 }
@@ -452,33 +452,27 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
 }
 
 if (withService) {
-char *ipv6_host = NULL;
+VIR_AUTOFREE(char *) ipv6_host = NULL;
 /* sasl_new_client demands the socket address to be in an odd format:
  * a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for
  * IPv6 only if no separator is passed to the function
  */
 if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6) {
 if (virAsprintf(_host, "[%s]", host) < 0)
-goto error;
+return NULL;
 }
 
 if (virAsprintf(, "%s%s%s",
 ipv6_host ? ipv6_host : host,
 separator ? separator : ":", port) == -1) {
-VIR_FREE(ipv6_host);
-goto error;
+return NULL;
 }
-
-VIR_FREE(ipv6_host);
 } else {
 if (VIR_STRDUP(addrstr, host) < 0)
-goto error;
+return NULL;
 }
 
 return addrstr;
-
- error:
-return NULL;
 }
 
 
@@ -759,24 +753,26 @@ virSocketAddrGetRange(virSocketAddrPtr start, 
virSocketAddrPtr end,
 int ret = 0;
 size_t i;
 virSocketAddr netmask;
-char *startStr = NULL, *endStr = NULL, *netStr = NULL;
+VIR_AUTOFREE(char *) startStr = NULL;
+VIR_AUTOFREE(char *) endStr = NULL;
+VIR_AUTOFREE(char *) netStr = NULL;
 
 if (start == NULL || end == NULL) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("NULL argument - %p %p"), start, end);
-goto error;
+return -1;
 }
 
 startStr = virSocketAddrFormat(start);
 endStr = virSocketAddrFormat(end);
 if (!startStr || !endStr)
-goto error; /*error already reported */
+return -1; /*error already reported */
 
 if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(end)) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("mismatch of address family in range %s - %s"),
startStr, endStr);
-goto error;
+return -1;
 }
 
 if (network) {
@@ -784,14 +780,14 @@ virSocketAddrGetRange(virSocketAddrPtr start, 
virSocketAddrPtr end,
  * network the range should be within
  */
 if (!(netStr = virSocketAddrFormat(network)))
-goto error;
+return -1;
 
 if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(network)) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("mismatch of address family in "
  "range %s - %s for network %s"),
startStr, endStr, netStr);
-goto error;
+return -1;
 }
 
 if (prefix < 0 ||
@@ -801,7 +797,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, 
virSocketAddrPtr end,
_("bad prefix %d for network %s when "
  " checking range %s - %s"),
prefix, netStr, startStr, endStr);
-goto error;
+return -1;
 }
 
 /* both start and end of range need to be within network */
@@ -811,7 +807,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, 
virSocketAddrPtr end,
_("range %s - %s is not entirely within "
  "network %s/%d"),
startStr, endStr, netStr, prefix);
-goto error;
+return -1;
 }
 
 if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) {
@@ -823,7 +819,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, 
virSocketAddrPtr end,
_("failed to construct broadcast or network "
  "address for network %s/%d"),
netStr, prefix);
-goto error;
+return -1;
 }
 
 /*