This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1969533 - Eclipse SWT Tree leaks native memory via gtk_tree_view_expand_row()
Summary: Eclipse SWT Tree leaks native memory via gtk_tree_view_expand_row()
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: gtk3
Version: 7.9
Hardware: x86_64
OS: Linux
medium
high
Target Milestone: rc
: ---
Assignee: Matthias Clasen
QA Contact: Desktop QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-08 14:40 UTC by Simeon Andreev
Modified: 2023-09-15 16:56 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-09-15 16:56:04 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   RHEL-4087 0 None Migrated None 2023-09-15 16:55:58 UTC

Description Simeon Andreev 2021-06-08 14:40:19 UTC
Description of problem:

Eclipse SWT Tree leaks native memory via gtk_tree_view_expand_row()


Version-Release number of selected component (if applicable):

We observe the leak with Eclipse 4.15, Eclipse 4.20 and Eclipse 4.21, as well as latest master from SWT. We assume the leak is seen with all Eclipse versions inbetween.

How reproducible:

To reproduce the leak, run the following SWT snippet:

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Tree Example");
    shell.setLayout(new FillLayout());
    Tree tree = new Tree(shell, SWT.NONE);
    tree.setItemCount(2);
    TreeItem item0 = tree.getItem(0);
    item0.setText("item0");
    TreeItem item1 = tree.getItem(1);
    item1.setText("item1");
    item1.setItemCount(6);
    TreeItem[] children = item1.getItems();
    for (int k = 0; k < children.length; ++k) {
        children[k].setText("child" + k);
    }
    item1.setExpanded(true);
    tree.setItemCount(1);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

jemalloc reports a memory leak as follows:

[240 bytes leaked]
je_prof_backtrace (/home/sandreev/git/misc/jemalloc/src/prof.c:636 (discriminator 2))
je_malloc_default (/home/sandreev/git/misc/jemalloc/src/jemalloc.c:2289)
g_malloc (??:?)
g_slice_alloc (??:?)
_gtk_rbnode_new.isra.2 (/usr/src/debug/gtk+-3.22.30/gtk/gtkrbtree.c:61)
_gtk_rbtree_insert_after (/usr/src/debug/gtk+-3.22.30/gtk/gtkrbtree.c:456)
gtk_tree_view_build_tree (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:9570)
gtk_tree_view_real_expand_row (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:12865)
gtk_tree_view_expand_row (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:12920)
Java_org_eclipse_swt_internal_gtk_GTK_gtk_1tree_1view_1expand_1row (??:?)
?? (??:0)

The same leak can be reproduced with the following GTK+ snippet:

// gcc -g tree.c `pkg-config --cflags --libs gtk+-3.0` -o tree

#include <gtk/gtk.h>

enum
{
  COL1 = 0,
  NUM_COLS
} ;

int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *scrolled_window;
  GtkWidget *view;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "delete_event", gtk_main_quit, NULL);

  gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);

  scrolled_window = gtk_scrolled_window_new(NULL, NULL);

  GtkCellRenderer     *renderer;

  view = gtk_tree_view_new ();

  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), -1, "column 1", renderer, "text", COL1, NULL);

  GtkTreeStore *treestore;
  GtkTreeIter   iter, child;

  treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);

  gtk_tree_store_append(treestore, &iter, NULL);
  gtk_tree_store_set(treestore, &iter, COL1, "item", -1);
  gtk_tree_store_append(treestore, &iter, NULL);
  gtk_tree_store_set(treestore, &iter, COL1, "item", -1);
  GtkTreePath *path = NULL;
  path = gtk_tree_model_get_path (GTK_TREE_MODEL(treestore), &iter);

  int j;
  for (j = 0; j < 6; ++j)
  {
    gtk_tree_store_append(treestore, &child, &iter);
    gtk_tree_store_set(treestore, &child, COL1, "child", -1);
  }

  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (treestore));

  if (path)
  {
    gtk_tree_view_expand_row(GTK_TREE_VIEW(view), path, FALSE);
    gtk_tree_path_free(path);
  }

  gtk_container_add (GTK_CONTAINER (window), scrolled_window);
  gtk_container_add (GTK_CONTAINER (scrolled_window), view);

  gtk_widget_show_all (window);

  GtkTreeIter iter1, child1;
  if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(treestore), &iter1, NULL, 1))
  {
    gtk_tree_store_remove(treestore, &iter1);
  }

  g_object_unref(treestore);

  gtk_main ();

  return 0;
}


jemalloc reports a memory leak as follows:

[240 bytes leaked]
je_prof_backtrace (/home/sandreev/git/misc/jemalloc/src/prof.c:636 (discriminator 2))
je_malloc_default (/home/sandreev/git/misc/jemalloc/src/jemalloc.c:2289)
g_malloc (??:?)
g_slice_alloc (??:?)
_gtk_rbnode_new.isra.2 (/usr/src/debug/gtk+-3.22.30/gtk/gtkrbtree.c:61)
_gtk_rbtree_insert_after (/usr/src/debug/gtk+-3.22.30/gtk/gtkrbtree.c:456)
gtk_tree_view_build_tree (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:9570)
gtk_tree_view_real_expand_row (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:12865)
gtk_tree_view_expand_row (/usr/src/debug/gtk+-3.22.30/gtk/gtktreeview.c:12920)
?? (??:0)
__libc_start_main (/usr/src/debug/glibc-2.17-c758a686/csu/../csu/libc-start.c:274)
?? (??:0)


Actual results:

Memory is leaked.

Expected results:

Memory is not leaked.

Additional info:

For more context (e.g. actual Eclipse user operations to run into the leak) see Eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=574065

Comment 2 Simeon Andreev 2021-06-08 14:42:20 UTC
We need either a GTK+  developer or a developer familiar with GTK3 API usage to look into this and let us know if:

1. This is a memory leak in GTK+.
1.1. In this case we need a fix in GTK+, which we require to resolve this support case.
2. SWT is supposed to use different API to remove tree rows, to avoid leaking memory.
2.1. We need to know what API we are supposed to use, to remove tree rows without causing a memory leak.
2.2. We need to know what to expect of the new code performance-wise. E.g. should we expect massive performance degradation?

RHEL support case: https://access.redhat.com/support/cases/#/case/02959748

Comment 3 Andrey Loskutov 2021-06-08 14:54:16 UTC
Simeon, please change title. It is not Eclipse nor SWT that leaks memory here, but GTK library via gtk_tree_view_expand_row(). Also the "component" is wrong, it must be GTK.

Comment 4 Simeon Andreev 2021-06-08 14:59:24 UTC
(In reply to Andrey Loskutov from comment #3)
> Simeon, please change title. It is not Eclipse nor SWT that leaks memory
> here, but GTK library via gtk_tree_view_expand_row(). Also the "component"
> is wrong, it must be GTK.

We don't know whether SWT is misusing GTK+ APIs to cause the memory leak, see comment 2.

Comment 8 RHEL Program Management 2023-09-15 16:52:06 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 9 RHEL Program Management 2023-09-15 16:56:04 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.


Note You need to log in before you can comment on or make changes to this bug.