From 4170c8d82fc7b922559ee2c7bb10d8da6318056a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 16 Jun 2023 21:19:15 +1000 Subject: [PATCH] tile: be extra careful when merging a tile into it's parent. When a parent tile gets down to just one child, the child is subsumed into the parent. This requires that the parent really is a tile pane. As pane_reparent() and change parantage, it is possible that it isn't. So add extra checks before assuming the types of things. Signed-off-by: NeilBrown --- lib-tile.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib-tile.c b/lib-tile.c index 5c756494..90bb1dd6 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -273,16 +273,11 @@ static int tile_destroy(struct pane *p safe) int pos, prevpos, nextpos; int remaining = 0; - if (ti->direction == Neither) { - /* Children have already been destroyed, just clean up */ - free(ti->name); ti->name = NULL; + if (ti->direction == Neither /* Root file a tile-set */ + || p->parent == p /* subsumbed hust being destroyed */ + || p->parent->handle != p->handle /* Some messed with parentage */ + ) return 1; - } - - if (p->parent == p) { - /* subsumed husk being destroyed */ - return 1; - } if (ti->direction == Vert) pos = p->y; @@ -306,7 +301,7 @@ static int tile_destroy(struct pane *p safe) remain = t; } /* There is always a sibling of a non-root */ - ASSERT(remaining > 0); + //ASSERT(remaining > 0); if (prev == NULL /* FIXME redundant */ && next) { /* next gets the space and focus*/ if (ti->direction == Horiz) @@ -362,7 +357,8 @@ static int tile_destroy(struct pane *p safe) tile_adjust(prev); } list_del(&ti->tiles); - if (remaining == 1 && remain->parent != remain) { + if (remaining == 1 && remain && remain->parent != remain && + remain->handle == p->handle) { struct tileinfo *ti2; enum dir tmp; /* Only one child left, must move it into parent. -- 2.39.5