From e8fb6b3325ee545312c092f0b103eea2424fce9f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 29 Jun 2018 19:36:22 +1000 Subject: [PATCH] Fix crash when moving last child of a container to workspace or output We were arranging a parent which may have been deleted by the reaper, which meant the `current` children list of the surviving parent had a dangling pointer. Instead, we now reap the workspace. --- sway/commands/move.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sway/commands/move.c b/sway/commands/move.c index 4ce8d089d..4061df3a4 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -90,6 +90,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, } free(ws_name); struct sway_container *old_parent = current->parent; + struct sway_container *old_ws = container_parent(current, C_WORKSPACE); struct sway_container *destination = seat_get_focus_inactive( config->handler_context.seat, ws); container_move_to(current, destination); @@ -99,8 +100,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, container_reap_empty(old_parent); container_reap_empty(destination->parent); + // TODO: Ideally we would arrange the surviving parent after reaping, + // but container_reap_empty does not return it, so we arrange the + // workspace instead. struct sway_transaction *txn = transaction_create(); - arrange_windows(old_parent, txn); + arrange_windows(old_ws, txn); arrange_windows(destination->parent, txn); transaction_commit(txn); @@ -129,13 +133,17 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, focus = destination->children->items[0]; } struct sway_container *old_parent = current->parent; + struct sway_container *old_ws = container_parent(current, C_WORKSPACE); container_move_to(current, focus); seat_set_focus(config->handler_context.seat, old_parent); container_reap_empty(old_parent); container_reap_empty(focus->parent); + // TODO: Ideally we would arrange the surviving parent after reaping, + // but container_reap_empty does not return it, so we arrange the + // workspace instead. struct sway_transaction *txn = transaction_create(); - arrange_windows(old_parent, txn); + arrange_windows(old_ws, txn); arrange_windows(focus->parent, txn); transaction_commit(txn);