-
Notifications
You must be signed in to change notification settings - Fork 185
[GTK3] Defer disposing Callbacks while GTK still has pointer to them #2684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akurtakov
merged 1 commit into
eclipse-platform:master
from
jonahgraham:sigsegv-on-copy
Oct 29, 2025
Merged
[GTK3] Defer disposing Callbacks while GTK still has pointer to them #2684
akurtakov
merged 1 commit into
eclipse-platform:master
from
jonahgraham:sigsegv-on-copy
Oct 29, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28542a0 to
f4437db
Compare
jonahgraham
added a commit
to jonahgraham/eclipse.platform.swt
that referenced
this pull request
Oct 28, 2025
test_printStackTrace overrides System.err with its own print stream to check functionality. But these tests did not restore System.err, so all System.err output for the rest of the test suite was lost into the last of these ByteArrayOutputStreams that was created. The tests themselves have little intrinsic value as they really test nothing of SWT itself, but it does help achieve code coverage. This was discovered when working on eclipse-platform#2684 as I could not see the output when running all the tests.
jonahgraham
added a commit
to jonahgraham/eclipse.platform.swt
that referenced
this pull request
Oct 28, 2025
test_printStackTrace overrides System.err with its own print stream to check functionality. But these tests did not restore System.err, so all System.err output for the rest of the test suite was lost into the last of these ByteArrayOutputStreams that was created. The tests themselves have little intrinsic value as they really test nothing of SWT itself, but it does help achieve code coverage. This was discovered when working on eclipse-platform#2684 as I could not see the output when running all the tests. Since we no longer swallow errors, the "For some reason, printing to System.err[...]" comment is resolved and we can print leaks to stderr again.
jonahgraham
added a commit
that referenced
this pull request
Oct 28, 2025
test_printStackTrace overrides System.err with its own print stream to check functionality. But these tests did not restore System.err, so all System.err output for the rest of the test suite was lost into the last of these ByteArrayOutputStreams that was created. The tests themselves have little intrinsic value as they really test nothing of SWT itself, but it does help achieve code coverage. This was discovered when working on #2684 as I could not see the output when running all the tests. Since we no longer swallow errors, the "For some reason, printing to System.err[...]" comment is resolved and we can print leaks to stderr again.
The calls to gtk_clipboard_set_with_owner (in ClipboardProxy.setData) means the GtkClipboard (in C side) has function pointers saved to the getFunc + clearFunc callbacks. Therefore, when we dispose ClipboardProxy we cannot dispose the callbacks until we know that GtkClipboard doesn't have a pointer to these callbacks. GtkClipboard clears these pointers in [clipboard_unset ](https://gitlab.gnome.org/GNOME/gtk/-/blob/716458e86a222f43e64f7a4feda37749f3469ee4/gtk/gtkclipboard.c#L755) and notifies us that the pointers are no longer stored by calling [clearFunc ](https://gitlab.gnome.org/GNOME/gtk/-/blob/716458e86a222f43e64f7a4feda37749f3469ee4/gtk/gtkclipboard.c#L782) Therefore, after disposing ClipboardProxy we need to defer disposing the callbacks until clearFunc has been called. We know if we have been called sufficiently (for both clipboards that could have a handle stored) when both clipboards no longer have data stored. If we don't defer the disposal it causes SIGSEGV or other undefined behavior. Fixes eclipse-platform#2675
f4437db to
50f2367
Compare
akurtakov
approved these changes
Oct 29, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The calls to gtk_clipboard_set_with_owner (in ClipboardProxy.setData) means the GtkClipboard (in C side) has function pointers saved to the getFunc + clearFunc callbacks.
Therefore, when we dispose ClipboardProxy we cannot dispose the callbacks until we know that GtkClipboard doesn't have a pointer to these callbacks. GtkClipboard clears these pointers in clipboard_unset and notifies us that the pointers are no longer stored by calling clearFunc
Therefore, after disposing ClipboardProxy we need to defer disposing the callbacks until clearFunc has been called.
We know if we have been called sufficiently (for both clipboards that could have a handle stored) when both clipboards no longer have data stored.
If we don't defer the disposal it causes SIGSEGV or other undefined behavior.
Fixes #2675