diff options
author | Simeon Andreev | 2021-05-21 09:43:19 +0000 |
---|---|---|
committer | Andrey Loskutov | 2021-06-07 16:17:19 +0000 |
commit | 845e7d1f3f135a66577827d15eed227d84cd26de (patch) | |
tree | 763bf7c3c6802b53edb76e7dbb0066f506795893 | |
parent | 0e5010e86bd35a230fd68999168e717221d357ec (diff) | |
download | eclipse.platform.swt-845e7d1f3f135a66577827d15eed227d84cd26de.tar.gz eclipse.platform.swt-845e7d1f3f135a66577827d15eed227d84cd26de.tar.xz eclipse.platform.swt-845e7d1f3f135a66577827d15eed227d84cd26de.zip |
Bug 573633 - [GTK3] Tree.setImage() leaks native memory
This change adds missing free calls to pixbuf objects created by
TreeItem.setImage() and TableItem.setImage(), preventing native memory
leaks.
According to the documentation of gtk_tree_store_set() and
gtk_list_store_set(), the call will reference the pixbuf in question.
Its therefore safe to unref it after the call, allowing GTK+ to
eventually free the memory on tree destruction.
Change-Id: Id54bedb6bbe6bed5075605ae7bbb3b69c48b00a3
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/180858
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
3 files changed, 12 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java index 4a471713b2..694a312cf4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java @@ -125,7 +125,9 @@ public static long createPixbuf(long surface) { double sy[] = new double[1]; Cairo.cairo_surface_get_device_scale(surface, sx, sy); if (sx[0] > 1 && sy[0] > 1){ + long oldPixbuf = pixbuf; pixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, width/(int)sx[0], height/(int)sy[0], GDK.GDK_INTERP_BILINEAR); + OS.g_object_unref(oldPixbuf); } } return pixbuf; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java index 794f0468ee..2bf439270a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java @@ -1257,6 +1257,11 @@ public void setImage(int index, Image image) { } int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; GTK.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1); + /* + * Bug 573633: gtk_list_store_set() will reference the handle. So we unref the pixbuf here, + * and leave the destruction of the handle to be done later on by the GTK+ tree. + */ + OS.g_object_unref(pixbuf); GTK.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_SURFACE, surface, -1); cached = true; /* diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index 2ac1bc0bea..1095828bc7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -1581,6 +1581,11 @@ public void setImage(int index, Image image) { } GTK.gtk_tree_store_set(parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, pixbuf, -1); + /* + * Bug 573633: gtk_tree_store_set() will reference the handle. So we unref the pixbuf here, + * and leave the destruction of the handle to be done later on by the GTK+ tree. + */ + OS.g_object_unref(pixbuf); GTK.gtk_tree_store_set(parent.modelHandle, handle, modelIndex + Tree.CELL_SURFACE, surface, -1); cached = true; updated = true; |