gsocketclient: Make connection_attempt_remove() safe to call twice

As spotted by Michael Catanzaro in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3394#note_1730123,
on the code path where a `ConnectionAttempt` is cancelled, it will
currently be removed from the `connection_attempts` list by the
cancellation code, and then *again* by the `if
(task_completed_or_cancelled ())` code in
`g_socket_client_connected_callback()`.

That would previously have resulted in a double-unref of the
`ConnectionAttempt`. So change `connection_attempt_remove()` to be a
no-op if the attempt isn’t found in `connection_attempts`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2023-05-02 12:19:35 +01:00 committed by Philip Withnall
parent 320c9d6d0d
commit a581de2ee7

View File

@ -1587,8 +1587,12 @@ connection_attempt_unref (gpointer pointer)
static void
connection_attempt_remove (ConnectionAttempt *attempt)
{
attempt->data->connection_attempts = g_slist_remove (attempt->data->connection_attempts, attempt);
connection_attempt_unref (attempt);
GSList *attempt_link = g_slist_find (attempt->data->connection_attempts, attempt);
if (attempt_link != NULL)
{
attempt->data->connection_attempts = g_slist_delete_link (attempt->data->connection_attempts, attempt_link);
connection_attempt_unref (attempt);
}
}
static void