Bug 567826 - [GTK] JVM crash on Display.dispose() due to Clipboard

If 'SWT.Dispose' handler is a bit slow, user might be able to switch to
other application and Ctrl+C there. When this happens, Linux calls
'ClipboardProxy.clearFunc()' with the following stack:

  Native: clipboard_unset() at gtk/gtkclipboard.c:782
  Native: selection_clear_event_cb() at gtk/gtkclipboard.c:424
  Native: <emit signal for 'GDK_SELECTION_CLEAR'>
  Native: gtk_widget_event_internal() at gtk/gtkwidget.c:7808
  Native: gtk_main_do_event() at gtk/gtkmain.c:1860
  Java:   org.eclipse.swt.internal.gtk.GTK._gtk_main_do_event()
  Java:   org.eclipse.swt.widgets.Display.eventProc()
  Java:   org.eclipse.swt.internal.gtk.OS._g_main_context_iteration()
  Java:   org.eclipse.swt.widgets.Display.readAndDispatch()
  Java:   org.eclipse.swt.widgets.Display.release()

If 'Callback' for 'clearFunc' is already disposed, JVM crashes.

The solution is to dispose callback after 'Display.readAndDispatch()' in
'Display.release()'.

This patch has a curious side effect: if 'SWT.Dispose' handler is slow,
Shell is now visible (and eventually shows "not responding") for its
duration. I understand that this is because 'gtk_clipboard_store()'
also does some unexpected event processing. I consider this side effect
as not a regression because the same behavior is seen when clipboard is
not owned by SWT by the time of 'Display.dispose()'.

Change-Id: I2cc11600f06030243e55d70f24b881dcb9b67503
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
3 files changed
tree: 1d77e011aaec2a0cd968af5c3350225d157608e1
  1. bundles/
  2. container/
  3. examples/
  4. features/
  5. local-build/
  6. tests/
  7. .gitignore
  8. CONTRIBUTING
  9. LICENSE
  10. NOTICE
  11. pom.xml
  12. README.md
README.md

Contributing to SWT

Thanks for your interest in this project.

Developer resources:

See the following description for how to contribute a feature or a bug fix to SWT.

Information regarding source code management, builds, coding standards, and more and be found under the following link.

Contributor License Agreement:

Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (CLA).

Contact:

Contact the project developers via the project's “dev” list.

Search for bugs:

This project uses Bugzilla to track ongoing development and issues.

Create a new bug:

Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome!