*/
void Curl_free_idnconverted_hostname(struct hostname *host)
{
- if(host->encalloc) {
- /* must be freed with idn2_free() if allocated by libidn */
- Curl_idn_free(host->encalloc);
- host->encalloc = NULL;
- }
+ Curl_safefree(host->encalloc);
}
#endif /* USE_IDN */
/* Check name for non-ASCII and convert hostname if we can */
if(!Curl_is_ASCII_name(host->name)) {
char *decoded;
- CURLcode result = idn_decode(host->name, &decoded);
- if(!result) {
- if(!*decoded) {
- /* zero length is a bad host name */
- Curl_idn_free(decoded);
- return CURLE_URL_MALFORMAT;
- }
- /* successful */
- host->encalloc = decoded;
- /* change the name pointer to point to the encoded hostname */
- host->name = host->encalloc;
- }
- else
+ CURLcode result = Curl_idn_decode(host->name, &decoded);
+ if(result)
return result;
+ /* successful */
+ host->name = host->encalloc = decoded;
}
#endif
return CURLE_OK;
void Curl_free_idnconverted_hostname(struct hostname *host);
CURLcode Curl_idn_decode(const char *input, char **output);
CURLcode Curl_idn_encode(const char *input, char **output);
-#ifdef USE_LIBIDN2
-#define Curl_idn_free(x) idn2_free(x)
-#else
-#define Curl_idn_free(x) free(x)
-#endif
#else
#define Curl_free_idnconverted_hostname(x)