From 0af276838c7400c9ff8bb936597741effbaf13a4 Mon Sep 17 00:00:00 2001 From: Hubert Tarasiuk Date: Mon, 6 Apr 2015 12:00:39 +0200 Subject: [PATCH 1/2] Remove memory leak in idn_encode * src/iri.c (idn_encode): The buffer allocated by remote_to_utf8 was never freed. --- src/iri.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/iri.c b/src/iri.c index dc1ebd0..b5e0a9e 100644 --- a/src/iri.c +++ b/src/iri.c @@ -225,19 +225,25 @@ locale_to_utf8 (const char *str) char * idn_encode (struct iri *i, char *host) { - char *new; + char *utf8_encoded; + char *ascii_encoded; int ret; /* Encode to UTF-8 if not done */ if (!i->utf8_encode) { - if (!remote_to_utf8 (i, (const char *) host, (const char **) &new)) + if (!remote_to_utf8 (i, (const char *) host, (const char **) &utf8_encoded)) return NULL; /* Nothing to encode or an error occured */ - host = new; } + else + utf8_encoded = host; /* toASCII UTF-8 NULL terminated string */ - ret = idna_to_ascii_8z (host, &new, IDNA_FLAGS); + ret = idna_to_ascii_8z (utf8_encoded, &ascii_encoded, IDNA_FLAGS); + + if (utf8_encoded != host) + xfree (utf8_encoded); + if (ret != IDNA_SUCCESS) { /* sXXXav : free new when needed ! */ @@ -246,7 +252,7 @@ idn_encode (struct iri *i, char *host) return NULL; } - return new; + return ascii_encoded; } /* Try to decode an "ASCII encoded" host. Return the new domain in the locale -- 2.3.5