mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
Remove memory leak in idn_encode.
* src/iri.c (idn_encode): Free buffer from remote_to_utf8 when needed; give meaningful names to variables; remove excessive comment.
This commit is contained in:
parent
ac40b84ee1
commit
bef5945202
15
src/iri.c
15
src/iri.c
@ -224,28 +224,29 @@ locale_to_utf8 (const char *str)
|
|||||||
char *
|
char *
|
||||||
idn_encode (struct iri *i, char *host)
|
idn_encode (struct iri *i, char *host)
|
||||||
{
|
{
|
||||||
char *new;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
char *ascii_encoded;
|
||||||
|
char *utf8_encoded = NULL;
|
||||||
|
|
||||||
/* Encode to UTF-8 if not done */
|
/* Encode to UTF-8 if not done */
|
||||||
if (!i->utf8_encode)
|
if (!i->utf8_encode)
|
||||||
{
|
{
|
||||||
if (!remote_to_utf8 (i, host, &new))
|
if (!remote_to_utf8 (i, host, &utf8_encoded))
|
||||||
return NULL; /* Nothing to encode or an error occured */
|
return NULL; /* Nothing to encode or an error occured */
|
||||||
host = new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* toASCII UTF-8 NULL terminated string */
|
/* Store in ascii_encoded the ASCII UTF-8 NULL terminated string */
|
||||||
ret = idna_to_ascii_8z (host, &new, IDNA_FLAGS);
|
ret = idna_to_ascii_8z (utf8_encoded ? utf8_encoded : host, &ascii_encoded, IDNA_FLAGS);
|
||||||
|
xfree (utf8_encoded);
|
||||||
|
|
||||||
if (ret != IDNA_SUCCESS)
|
if (ret != IDNA_SUCCESS)
|
||||||
{
|
{
|
||||||
/* sXXXav : free new when needed ! */
|
|
||||||
logprintf (LOG_VERBOSE, _("idn_encode failed (%d): %s\n"), ret,
|
logprintf (LOG_VERBOSE, _("idn_encode failed (%d): %s\n"), ret,
|
||||||
quote (idna_strerror (ret)));
|
quote (idna_strerror (ret)));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new;
|
return ascii_encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to decode an "ASCII encoded" host. Return the new domain in the locale
|
/* Try to decode an "ASCII encoded" host. Return the new domain in the locale
|
||||||
|
Loading…
Reference in New Issue
Block a user