Merge branch 'gai_strerror-thread-safety' into 'master'

gresolver: Don’t use gai_strerror() on Windows, as it isn’t threadsafe

See merge request GNOME/glib!737
This commit is contained in:
Michael Catanzaro 2019-03-21 14:37:18 +00:00
commit abeac84105
2 changed files with 32 additions and 3 deletions

View File

@ -340,9 +340,19 @@ handle_ip_address (const char *hostname,
if (inet_aton (hostname, &ip4addr)) if (inet_aton (hostname, &ip4addr))
#endif #endif
{ {
#ifdef G_OS_WIN32
gchar *error_message = g_win32_error_message (WSAHOST_NOT_FOUND);
#else
const gchar *error_message = gai_strerror (EAI_NONAME);
#endif
g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND, g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
_("Error resolving “%s”: %s"), _("Error resolving “%s”: %s"),
hostname, gai_strerror (EAI_NONAME)); hostname, error_message);
#ifdef G_OS_WIN32
g_free (error_message);
#endif
return TRUE; return TRUE;
} }

View File

@ -154,11 +154,21 @@ do_lookup_by_name (GTask *task,
} }
else else
{ {
#ifdef G_OS_WIN32
gchar *error_message = g_win32_error_message (WSAGetLastError ());
#else
const gchar *error_message = gai_strerror (retval);
#endif
g_task_return_new_error (task, g_task_return_new_error (task,
G_RESOLVER_ERROR, G_RESOLVER_ERROR,
g_resolver_error_from_addrinfo_error (retval), g_resolver_error_from_addrinfo_error (retval),
_("Error resolving “%s”: %s"), _("Error resolving “%s”: %s"),
hostname, gai_strerror (retval)); hostname, error_message);
#ifdef G_OS_WIN32
g_free (error_message);
#endif
} }
if (res) if (res)
@ -310,14 +320,23 @@ do_lookup_by_address (GTask *task,
{ {
gchar *phys; gchar *phys;
#ifdef G_OS_WIN32
gchar *error_message = g_win32_error_message (WSAGetLastError ());
#else
const gchar *error_message = gai_strerror (retval);
#endif
phys = g_inet_address_to_string (address); phys = g_inet_address_to_string (address);
g_task_return_new_error (task, g_task_return_new_error (task,
G_RESOLVER_ERROR, G_RESOLVER_ERROR,
g_resolver_error_from_addrinfo_error (retval), g_resolver_error_from_addrinfo_error (retval),
_("Error reverse-resolving “%s”: %s"), _("Error reverse-resolving “%s”: %s"),
phys ? phys : "(unknown)", phys ? phys : "(unknown)",
gai_strerror (retval)); error_message);
g_free (phys); g_free (phys);
#ifdef G_OS_WIN32
g_free (error_message);
#endif
} }
} }