From 6ef493b19ee0468dd2884940e7ad50172213fc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Sat, 8 Apr 2017 11:05:55 +0200 Subject: [PATCH] Fix use of idn2_free() * src/connect.c (connect_to_ip): Use xfree() instead of idn2_free() * src/host.c (lookup_host): Use xfree() instead of idn2_free() * src/iri.h: Do not include idn2.h * src/url.c (url_free): Use xfree() instead of idn2_free() * src/url.h (struct url): Remove 'idn_allocated' from struct Reported-by: Gisle Vanem --- src/connect.c | 11 ++--------- src/host.c | 11 ++--------- src/iri.h | 2 -- src/url.c | 8 +------- src/url.h | 4 ---- 5 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/connect.c b/src/connect.c index 7e181716..d665d6d9 100644 --- a/src/connect.c +++ b/src/connect.c @@ -56,10 +56,6 @@ as that of the covered work. */ #include #include -#ifdef ENABLE_IRI -#include -#endif - #include "utils.h" #include "host.h" #include "connect.h" @@ -280,11 +276,8 @@ connect_to_ip (const ip_address *ip, int port, const char *print) if (opt.enable_iri && (name = idn_decode ((char *) print)) != NULL) { - int len = strlen (print) + strlen (name) + 4; - str = xmalloc (len); - snprintf (str, len, "%s (%s)", name, print); - str[len-1] = '\0'; - idn2_free (name); + str = aprintf ("%s (%s)", name, print); + xfree (name); } logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "), diff --git a/src/host.c b/src/host.c index 9f551c72..ccc6349d 100644 --- a/src/host.c +++ b/src/host.c @@ -57,10 +57,6 @@ as that of the covered work. */ #include -#ifdef ENABLE_IRI -#include -#endif - #include "utils.h" #include "host.h" #include "url.h" @@ -846,11 +842,8 @@ lookup_host (const char *host, int flags) if (opt.enable_iri && (name = idn_decode ((char *) host)) != NULL) { - int len = strlen (host) + strlen (name) + 4; - str = xmalloc (len); - snprintf (str, len, "%s (%s)", name, host); - str[len-1] = '\0'; - idn2_free (name); + str = aprintf ("%s (%s)", name, host); + xfree (name); } logprintf (LOG_VERBOSE, _("Resolving %s... "), diff --git a/src/iri.h b/src/iri.h index ba64a275..fb994ee1 100644 --- a/src/iri.h +++ b/src/iri.h @@ -40,8 +40,6 @@ struct iri { #ifdef ENABLE_IRI -# include - char *parse_charset (const char *str); const char *find_locale (void); bool check_encoding_name (const char *encoding); diff --git a/src/url.c b/src/url.c index 07b32a10..7f2376ff 100644 --- a/src/url.c +++ b/src/url.c @@ -944,7 +944,6 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode) { xfree (u->host); u->host = new; - u->idn_allocated = true; host_modified = true; } } @@ -1223,12 +1222,7 @@ url_free (struct url *url) { if (url) { - if (url->idn_allocated) { - idn2_free (url->host); /* A dummy if !defined(ENABLE_IRI) */ - url->host = NULL; - } - else - xfree (url->host); + xfree (url->host); xfree (url->path); xfree (url->url); diff --git a/src/url.h b/src/url.h index 94d1528c..ad58739b 100644 --- a/src/url.h +++ b/src/url.h @@ -99,10 +99,6 @@ struct url /* Username and password (unquoted). */ char *user; char *passwd; - - /* 'host' is allocated by idn2_lookup_u8() via idn_encode(). - * Call 'idn2_free()' to free this memory. */ - bool idn_allocated; }; /* Function declarations */