guri: Simplify memory management in parse_host()

This introduces no functional changes, but makes the memory ownership a
little clearer and reduces the length of the code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2020-09-30 17:46:02 +01:00
parent 58fce4b92b
commit 17a53f2fc7

View File

@ -511,7 +511,7 @@ parse_host (const gchar *start,
gchar **out, gchar **out,
GError **error) GError **error)
{ {
gchar *decoded, *host; gchar *decoded = NULL, *host;
gchar *addr = NULL; gchar *addr = NULL;
if (*start == '[') if (*start == '[')
@ -537,7 +537,7 @@ parse_host (const gchar *start,
if (!uri_normalize (&decoded, start, length, flags, if (!uri_normalize (&decoded, start, length, flags,
G_URI_ERROR_BAD_HOST, error)) G_URI_ERROR_BAD_HOST, error))
return FALSE; return FALSE;
host = decoded; host = g_steal_pointer (&decoded);
goto ok; goto ok;
} }
@ -559,18 +559,16 @@ parse_host (const gchar *start,
} }
if (g_hostname_is_non_ascii (decoded)) if (g_hostname_is_non_ascii (decoded))
{ host = g_hostname_to_ascii (decoded);
host = g_hostname_to_ascii (decoded);
g_free (decoded);
}
else else
host = decoded; host = g_steal_pointer (&decoded);
ok: ok:
if (out) if (out)
*out = host; *out = g_steal_pointer (&host);
else g_free (host);
g_free (host); g_free (decoded);
return TRUE; return TRUE;
} }