gsocketclient: Fix potential critical when cancelling connect

We are manually tracking the completion state of the connect task
so avoid just calling g_task_return_error_if_cancelled() without
checking that.

Fixes #1747
This commit is contained in:
Patrick Griffis 2019-04-16 10:22:35 -07:00 committed by Patrick Griffis
parent c95e2ae9c9
commit 313e7cbad7

View File

@ -1427,15 +1427,24 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
data->connection = (GIOStream *)wrapper_connection;
}
if (!g_task_return_error_if_cancelled (data->task))
if (!data->completed)
{
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection);
g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref);
}
else
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
GError *error = NULL;
if (g_cancellable_set_error_if_cancelled (g_task_get_cancellable (data->task), &error))
{
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
g_task_return_error (data->task, g_steal_pointer (&error));
}
else
{
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection);
g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref);
}
data->completed = TRUE;
}
data->completed = TRUE;
g_object_unref (data->task);
}