gcancellable: remove sketchy source ref/unref

These refcount changes cannot possibly fix any race condition because
there is no guarantee that the g_source_ref() will be called in this
thread before any g_source_unref() that might happen on another thread.
We would have to take the ref sooner for it to be effective.

It's also not clear why we take a ref at all, since the source is
already being disposed and there's no explanation of why we should
resurrect it here. It can't be finialized until the call to dispose is
finished, so it's unclear what we are guarding against.

I'm not sure about the correctness of this code and make no promises
that there are no bugs here, but I think this change shouldn't make
anything worse.
This commit is contained in:
Michael Catanzaro 2025-02-06 12:14:34 -06:00
parent 00f54b1bcc
commit 222546ddd0
No known key found for this signature in database
GPG Key ID: 7F71B64279363298

View File

@ -742,15 +742,12 @@ cancellable_source_dispose (GSource *source)
* dangling GCancellableSource pointer.
*
* Eliminate that race by waiting to ensure that our cancelled
* callback has been called, keeping a temporary ref, so that
* there's no risk that we're unreffing something that is still
* going to be used.
* callback has been called, so that there's no risk that we're
* unreffing something that is still going to be used.
*/
g_source_ref (source);
while (!g_atomic_int_get (&cancellable_source->cancelled_callback_called))
;
g_source_unref (source);
}
g_clear_signal_handler (&cancellable_source->cancelled_handler, cancellable);