Bug 573432 - [GTK3] Text/Combo.eventWindow() and Shell.showWidget() leak

This change adjusts code in Combo.eventWindow(), Text.eventWindow() and
Shell.showWidget(), to ensure the handle returned by native methods
(gdk_window_get_children() and gtk_container_get_children()) is always
freed. This avoids native memory leaks.

Change-Id: Ifd68fc72df4ebab21f3c8f264c25ae56aa0ee140
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/180362
Reviewed-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Tested-by: Platform Bot <platform-bot@eclipse.org>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
index c5dfb0ae..1290655 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
@@ -1057,9 +1057,10 @@
 	// Find the internal GDK_INPUT_ONLY window
 	long children = GDK.gdk_window_get_children (window);
 	if (children != 0) {
+		long childrenIterator = children;
 		do {
-			window = OS.g_list_data (children);
-		} while ((children = OS.g_list_next (children)) != 0);
+			window = OS.g_list_data (childrenIterator);
+		} while ((childrenIterator = OS.g_list_next (childrenIterator)) != 0);
 	}
 	OS.g_list_free (children);
 
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index 171106a..3afd040 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -3004,9 +3004,10 @@
 			}
 		} else {
 			long list = GTK3.gtk_container_get_children (shellHandle);
-			while (list != 0) {
-				GTK3.gtk_container_remove (shellHandle, OS.g_list_data (list));
-				list = OS.g_list_next(list);
+			long listIterator = list;
+			while (listIterator != 0) {
+				GTK3.gtk_container_remove (shellHandle, OS.g_list_data (listIterator));
+				listIterator = OS.g_list_next(listIterator);
 			}
 			OS.g_list_free (list);
 		}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index d4a7f0d..9df332a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -829,6 +829,7 @@
 		long window = super.paintWindow ();
 		long children = GDK.gdk_window_get_children (window);
 		if (children != 0) {
+			long childrenIterator = children;
 			/*
 			 * When search or cancel icons are added to Text, those
 			 * icon window(s) are added to the beginning of the list.
@@ -836,8 +837,8 @@
 			 * browse to the end of the list.
 			 */
 			do {
-				window = OS.g_list_data (children);
-			} while ((children = OS.g_list_next (children)) != 0);
+				window = OS.g_list_data (childrenIterator);
+			} while ((childrenIterator = OS.g_list_next (childrenIterator)) != 0);
 		}
 		OS.g_list_free (children);
 		return window;