From 7e400a886e4dd809f002941acb43ff3ba870b6aa Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Sep 2020 17:50:38 +0100 Subject: [PATCH] guri: Refactor error handling in parse_ip_literal() Having the goto labels at the bottom of a function makes things a little more readable. This introduces no functional changes. Signed-off-by: Philip Withnall --- glib/guri.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/glib/guri.c b/glib/guri.c index 6c5e579cb..056b86a2e 100644 --- a/glib/guri.c +++ b/glib/guri.c @@ -466,14 +466,7 @@ parse_ip_literal (const gchar *start, gchar *addr = NULL; if (start[length - 1] != ']') - { - bad_ipv6_literal: - g_free (addr); - g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST, - _("Invalid IPv6 address ā€˜%.*s’ in URI"), - (gint)length, start); - return FALSE; - } + goto bad_ipv6_literal; addr = g_strndup (start + 1, length - 2); @@ -499,9 +492,18 @@ parse_ip_literal (const gchar *start, /* Success */ if (out != NULL) *out = g_steal_pointer (&addr); + g_free (addr); return TRUE; + +bad_ipv6_literal: + g_free (addr); + g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST, + _("Invalid IPv6 address ā€˜%.*s’ in URI"), + (gint)length, start); + + return FALSE; } static gboolean