After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 764845 - GDK: gdk_window_reparent creates circular reference in 'children' list
GDK: gdk_window_reparent creates circular reference in 'children' list
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
3.18.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-04-10 13:05 UTC by Jeremy Tan
Modified: 2016-04-12 12:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example source that exhibits issue (1.74 KB, text/plain)
2016-04-11 00:16 UTC, Jeremy Tan
  Details
GDK W32: Deduplicate reparenting (1.67 KB, patch)
2016-04-11 07:12 UTC, LRN
committed Details | Review

Description Jeremy Tan 2016-04-10 13:05:44 UTC
This bug has been present at least since 8306d26714514f001d49b1cefc182459a44d9724.

Referring to lines 1748-1751 in gdkwindow-win32.c as of adff59843b3cd511557ba5a578d2e75e685b3bed (https://github.com/GNOME/gtk/blob/adff59843b3cd511557ba5a578d2e75e685b3bed/gdk/win32/gdkwindow-win32.c#L1748), it updates both the old parent's child window list and the new parent's child window list.

However, in the generic reparenting code in gdkwindow.c (lines 1642-1649 and line 1655 as of adff59843b3cd511557ba5a578d2e75e685b3bed (https://github.com/GNOME/gtk/blob/adff59843b3cd511557ba5a578d2e75e685b3bed/gdk/gdkwindow.c#L1642, https://github.com/GNOME/gtk/blob/adff59843b3cd511557ba5a578d2e75e685b3bed/gdk/gdkwindow.c#L1655), these properties are updated again.

While this duplicated code has no effect for the old parent, by updating the new parent's child list again, a circular reference is created in the list of children.

One effect of this is that calling gdk_window_show on the new parent will result in it entering an infinite loop as it tries to traverse the children.

One potential fix would be to remove this code from gdkwindow-win32.c and leave it up to the generic code the layer above.

I don't know if this affects other backends or not - I only know that it is an issue on Windows.
Comment 1 LRN 2016-04-10 13:29:58 UTC
Git blame says that this code was modified in
9bda0532
and before that it was modified in
1d838f58
and before that it was modified in
8e06c4d7
and
638ebcee
which just moved it from somewhere else (that's when gdkwindow-win32.c was created).

I don't know anything about this code in isolation. My best bet would be to see what other backends do (or don't do) and make W32 backend conform with that.
Comment 2 LRN 2016-04-10 17:18:04 UTC
Other backends either don't support reparenting, or they don't change the child list of the parent. Quartz does, but it changes its own internal z-order-sorted list, not the generic gdkwindow children list.

The original code dates back to 1999 and tml, and last meaningful change was in 2011 - https://git.gnome.org/browse/gtk+/commit/?id=1d838f58

I think that removing these two lines should be sufficient, as it's clearly a duplicate of what generic gdkwindow code does.

Though reparenting is somewhat rarely-used functionality, AFAIU. Do we have tests for it?
Comment 3 Jeremy Tan 2016-04-11 00:16:33 UTC
Created attachment 325692 [details]
Example source that exhibits issue

I don't know about existing tests, but I've attached a sample program that exhibits this issue. On builds of GDK that are unpatched, the code will hang on the first call to gdk_window_show (line 54).
Comment 4 LRN 2016-04-11 07:12:08 UTC
Created attachment 325698 [details] [review]
GDK W32: Deduplicate reparenting

This should do the trick.
Comment 5 Ignacio Casal Quinteiro (nacho) 2016-04-11 07:21:42 UTC
Review of attachment 325698 [details] [review]:

Looks good to me but a review from Matthias would be great here
Comment 6 Alexander Larsson 2016-04-12 12:47:33 UTC
Review of attachment 325698 [details] [review]:

Looks good to me
Comment 7 LRN 2016-04-12 12:58:39 UTC
Attachment 325698 [details] pushed as c2aa7d0 - GDK W32: Deduplicate reparenting