diff --git a/src/connect.c b/src/connect.c index a343f668..c9dd6fb2 100644 --- a/src/connect.c +++ b/src/connect.c @@ -54,6 +54,11 @@ as that of the covered work. */ #include #include #include + +#ifdef ENABLE_IRI +#include +#endif + #include "utils.h" #include "host.h" #include "connect.h" @@ -278,7 +283,7 @@ connect_to_ip (const ip_address *ip, int port, const char *print) str = xmalloc (len); snprintf (str, len, "%s (%s)", name, print); str[len-1] = '\0'; - xfree (name); + idn_free (name); } logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "), diff --git a/src/host.c b/src/host.c index d0dbe503..df31f3ff 100644 --- a/src/host.c +++ b/src/host.c @@ -57,6 +57,10 @@ as that of the covered work. */ #include +#ifdef ENABLE_IRI +#include +#endif + #include "utils.h" #include "host.h" #include "url.h" @@ -741,7 +745,7 @@ lookup_host (const char *host, int flags) str = xmalloc (len); snprintf (str, len, "%s (%s)", name, host); str[len-1] = '\0'; - xfree (name); + idn_free (name); } logprintf (LOG_VERBOSE, _("Resolving %s... "), diff --git a/src/iri.c b/src/iri.c index 92186fc2..38c8c6ee 100644 --- a/src/iri.c +++ b/src/iri.c @@ -35,6 +35,7 @@ as that of the covered work. */ #include #include #include +#include #include #include "utils.h" diff --git a/src/iri.h b/src/iri.h index e759e456..dbd48072 100644 --- a/src/iri.h +++ b/src/iri.h @@ -39,6 +39,9 @@ struct iri { #ifdef ENABLE_IRI +# include +# include + char *parse_charset (char *str); char *find_locale (void); bool check_encoding_name (char *encoding); @@ -62,6 +65,7 @@ extern struct iri dummy_iri; #define locale_to_utf8(str) (str) #define idn_encode(a,b) NULL #define idn_decode(str) NULL +#define idn_free(str) ((void)0) #define remote_to_utf8(a,b,c) false #define iri_new() (&dummy_iri) #define iri_dup(a) (&dummy_iri) diff --git a/src/url.c b/src/url.c index 466ee77d..e95f830a 100644 --- a/src/url.c +++ b/src/url.c @@ -897,6 +897,7 @@ 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; } } @@ -1175,7 +1176,13 @@ url_free (struct url *url) { if (url) { - xfree (url->host); + if (url->idn_allocated) { + idn_free (url->host); /* A dummy if !defined(ENABLE_IRI) */ + url->host = NULL; + } + else + xfree (url->host); + xfree (url->path); xfree (url->url); diff --git a/src/url.h b/src/url.h index 1627be9e..ed91bb1b 100644 --- a/src/url.h +++ b/src/url.h @@ -95,6 +95,10 @@ struct url /* Username and password (unquoted). */ char *user; char *passwd; + + /* 'host' is allocated by idna_to_ascii_8z() via idn_encode(). + * Call 'idn_free()' to free this memory. */ + bool idn_allocated; }; /* Function declarations */