That fixes use after free spotted here: https://gitlab.winehq.org/wine/wine/-/merge_requests/10992#note_142086 I checked on Windows with heap debug flags but on Windows this implicit backbuffer1 surface interface seems to be not possible to free at all after this test. While refcount is 0 interface is refusing to go away. That maybe has something to do with spurious refcount increase on chain start after deleting the tail element from chain (maybe there are additional inner references which don't go away after zeroing external refcount). Since this only happens in the extreme corner case unlikely used in practice (which I added to tests only in attempt to find generic logic in attachment behaviour) I guess we might not be concerned with this difference in implementation. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11060#note_142115