Skip to content

Conversation

@jonahgraham
Copy link
Contributor

@jonahgraham jonahgraham commented Oct 28, 2025

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

Test Results

  118 files  ±0    118 suites  ±0   13m 34s ⏱️ -7s
4 650 tests +3  4 632 ✅ +3  18 💤 ±0  0 ❌ ±0 
  330 runs  ±0    326 ✅ ±0   4 💤 ±0  0 ❌ ±0 

Results for commit 50f2367. ± Comparison against base commit 92db85c.

♻️ This comment has been updated with latest results.

@jonahgraham jonahgraham self-assigned this Oct 28, 2025
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 jonahgraham requested a review from akurtakov October 28, 2025 19:38
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
@akurtakov akurtakov merged commit 74c5bae into eclipse-platform:master Oct 29, 2025
17 checks passed
@jonahgraham jonahgraham deleted the sigsegv-on-copy branch October 29, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[GTK3] SIGSEGV in Text.copy (and similar methods)

2 participants