idn: use idn_free() to free allocated libidn memory

xfree() might crash on libidn memory on Windows.

From 'man idn_free':
"Under Windows, different parts of the same application may use different
 heap memory, and then it is important to deallocate memory allocated within
 the same  module  that  allocated it. This function makes that possible."
This commit is contained in:
Gisle Vanem 2015-02-13 13:24:19 +01:00 committed by Tim Rühsen
parent 3d8e765c1d
commit 9df2250f4c
6 changed files with 28 additions and 3 deletions

View File

@ -54,6 +54,11 @@ as that of the covered work. */
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#ifdef ENABLE_IRI
#include <idn-free.h>
#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... "),

View File

@ -57,6 +57,10 @@ as that of the covered work. */
#include <errno.h>
#ifdef ENABLE_IRI
#include <idn-free.h>
#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... "),

View File

@ -35,6 +35,7 @@ as that of the covered work. */
#include <iconv.h>
#include <stringprep.h>
#include <idna.h>
#include <idn-free.h>
#include <errno.h>
#include "utils.h"

View File

@ -39,6 +39,9 @@ struct iri {
#ifdef ENABLE_IRI
# include <idna.h>
# include <idn-free.h>
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)

View File

@ -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);

View File

@ -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 */