]> git.sur5r.net Git - i3/i3/blobdiff - src/commands.c
Merge branch 'next' into master
[i3/i3] / src / commands.c
index 78dc2159e75221ed76451da9f7f38c1a02430379..c9580c28f2cd50a8523a18338f208f4209a5b3c9 100644 (file)
 #include <float.h>
 #include <stdarg.h>
 
+#ifdef I3_ASAN_ENABLED
+#include <sanitizer/lsan_interface.h>
+#endif
+
 #include "all.h"
 #include "shmlog.h"
 
         }                                               \
     } while (0)
 
+/** If an error occured during parsing of the criteria, we want to exit instead
+ * of relying on fallback behavior. See #2091. */
+#define HANDLE_INVALID_MATCH                                   \
+    do {                                                       \
+        if (current_match->error != NULL) {                    \
+            yerror("Invalid match: %s", current_match->error); \
+            return;                                            \
+        }                                                      \
+    } while (0)
+
 /** When the command did not include match criteria (!), we use the currently
  * focused container. Do not confuse this case with a command which included
  * criteria but which did not match any windows. This macro has to be called in
  */
 #define HANDLE_EMPTY_MATCH                              \
     do {                                                \
+        HANDLE_INVALID_MATCH;                           \
+                                                        \
         if (match_is_empty(current_match)) {            \
+            while (!TAILQ_EMPTY(&owindows)) {           \
+                owindow *ow = TAILQ_FIRST(&owindows);   \
+                TAILQ_REMOVE(&owindows, ow, owindows);  \
+                free(ow);                               \
+            }                                           \
             owindow *ow = smalloc(sizeof(owindow));     \
             ow->con = focused;                          \
             TAILQ_INIT(&owindows);                      \
@@ -121,102 +142,6 @@ static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
     return workspace;
 }
 
-// This code is commented out because we might recycle it for popping up error
-// messages on parser errors.
-#if 0
-static pid_t migration_pid = -1;
-
-/*
- * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
- * it exited (or could not be started, depending on the exit code).
- *
- */
-static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
-    ev_child_stop(EV_A_ watcher);
-    if (!WIFEXITED(watcher->rstatus)) {
-        fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
-        return;
-    }
-
-    int exitcode = WEXITSTATUS(watcher->rstatus);
-    printf("i3-nagbar process exited with status %d\n", exitcode);
-    if (exitcode == 2) {
-        fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
-    }
-
-    migration_pid = -1;
-}
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-/*
- * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
- * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
- *
- */
-static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
-    if (migration_pid != -1) {
-        LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
-        kill(migration_pid, SIGKILL);
-    }
-}
-#endif
-
-void cmd_MIGRATION_start_nagbar(void) {
-    if (migration_pid != -1) {
-        fprintf(stderr, "i3-nagbar already running.\n");
-        return;
-    }
-    fprintf(stderr, "Starting i3-nagbar, command parsing differs from expected output.\n");
-    ELOG("Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
-    ELOG("i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
-    ELOG("FYI: Your i3 version is " I3_VERSION "\n");
-    migration_pid = fork();
-    if (migration_pid == -1) {
-        warn("Could not fork()");
-        return;
-    }
-
-    /* child */
-    if (migration_pid == 0) {
-        char *pageraction;
-        sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
-        char *argv[] = {
-            NULL, /* will be replaced by the executable path */
-            "-t",
-            "error",
-            "-m",
-            "You found a parsing error. Please, please, please, report it!",
-            "-b",
-            "show errors",
-            pageraction,
-            NULL
-        };
-        exec_i3_utility("i3-nagbar", argv);
-    }
-
-    /* parent */
-    /* install a child watcher */
-    ev_child *child = smalloc(sizeof(ev_child));
-    ev_child_init(child, &nagbar_exited, migration_pid, 0);
-    ev_child_start(main_loop, child);
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-    /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
-     * still running) */
-    ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
-    ev_cleanup_init(cleanup, nagbar_cleanup);
-    ev_cleanup_start(main_loop, cleanup);
-#endif
-}
-
-#endif
-
 /*******************************************************************************
  * Criteria functions.
  ******************************************************************************/
@@ -282,27 +207,61 @@ void cmd_criteria_match_windows(I3_CMD) {
         next = TAILQ_NEXT(next, owindows);
 
         DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
+
+        /* We use this flag to prevent matching on window-less containers if
+         * only window-specific criteria were specified. */
+        bool accept_match = false;
+
         if (current_match->con_id != NULL) {
+            accept_match = true;
+
             if (current_match->con_id == current->con) {
-                DLOG("matches container!\n");
-                TAILQ_INSERT_TAIL(&owindows, current, owindows);
+                DLOG("con_id matched.\n");
             } else {
-                DLOG("doesnt match\n");
-                free(current);
+                DLOG("con_id does not match.\n");
+                FREE(current);
+                continue;
             }
-        } else if (current_match->mark != NULL && current->con->mark != NULL &&
-                   regex_matches(current_match->mark, current->con->mark)) {
-            DLOG("match by mark\n");
-            TAILQ_INSERT_TAIL(&owindows, current, owindows);
-        } else {
-            if (current->con->window && match_matches_window(current_match, current->con->window)) {
+        }
+
+        if (current_match->mark != NULL && !TAILQ_EMPTY(&(current->con->marks_head))) {
+            accept_match = true;
+            bool matched_by_mark = false;
+
+            mark_t *mark;
+            TAILQ_FOREACH(mark, &(current->con->marks_head), marks) {
+                if (!regex_matches(current_match->mark, mark->name))
+                    continue;
+
+                DLOG("match by mark\n");
+                matched_by_mark = true;
+                break;
+            }
+
+            if (!matched_by_mark) {
+                DLOG("mark does not match.\n");
+                FREE(current);
+                continue;
+            }
+        }
+
+        if (current->con->window != NULL) {
+            if (match_matches_window(current_match, current->con->window)) {
                 DLOG("matches window!\n");
-                TAILQ_INSERT_TAIL(&owindows, current, owindows);
+                accept_match = true;
             } else {
-                DLOG("doesnt match\n");
-                free(current);
+                DLOG("doesn't match\n");
+                FREE(current);
+                continue;
             }
         }
+
+        if (accept_match) {
+            TAILQ_INSERT_TAIL(&owindows, current, owindows);
+        } else {
+            FREE(current);
+            continue;
+        }
     }
 
     TAILQ_FOREACH(current, &owindows, owindows) {
@@ -397,16 +356,17 @@ void cmd_move_con_to_workspace_back_and_forth(I3_CMD) {
 }
 
 /*
- * Implementation of 'move [window|container] [to] workspace <name>'.
+ * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace <name>'.
  *
  */
-void cmd_move_con_to_workspace_name(I3_CMD, const char *name) {
+void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
     if (strncasecmp(name, "__", strlen("__")) == 0) {
         LOG("You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
         ysuccess(false);
         return;
     }
 
+    const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
     owindow *current;
 
     /* We have nothing to move:
@@ -426,7 +386,8 @@ void cmd_move_con_to_workspace_name(I3_CMD, const char *name) {
     /* get the workspace */
     Con *ws = workspace_get(name, NULL);
 
-    ws = maybe_auto_back_and_forth_workspace(ws);
+    if (!no_auto_back_and_forth)
+        ws = maybe_auto_back_and_forth_workspace(ws);
 
     HANDLE_EMPTY_MATCH;
 
@@ -441,10 +402,11 @@ void cmd_move_con_to_workspace_name(I3_CMD, const char *name) {
 }
 
 /*
- * Implementation of 'move [window|container] [to] workspace number <name>'.
+ * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace number <name>'.
  *
  */
-void cmd_move_con_to_workspace_number(I3_CMD, const char *which) {
+void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
+    const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
     owindow *current;
 
     /* We have nothing to move:
@@ -477,7 +439,8 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which) {
         workspace = workspace_get(which, NULL);
     }
 
-    workspace = maybe_auto_back_and_forth_workspace(workspace);
+    if (!no_auto_back_and_forth)
+        workspace = maybe_auto_back_and_forth_workspace(workspace);
 
     HANDLE_EMPTY_MATCH;
 
@@ -609,7 +572,7 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way
 
     while (current->type != CT_WORKSPACE &&
            current->type != CT_FLOATING_CON &&
-           con_orientation(current->parent) != search_orientation)
+           (con_orientation(current->parent) != search_orientation || con_num_children(current->parent) == 1))
         current = current->parent;
 
     /* get the default percentage */
@@ -753,8 +716,8 @@ void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
  * Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
  *
  */
-void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) {
-    DLOG("border style should be changed to %s with border width %s\n", border_style_str, border_width);
+void cmd_border(I3_CMD, const char *border_style_str, long border_width) {
+    DLOG("border style should be changed to %s with border width %ld\n", border_style_str, border_width);
     owindow *current;
 
     HANDLE_EMPTY_MATCH;
@@ -762,39 +725,35 @@ void cmd_border(I3_CMD, const char *border_style_str, const char *border_width)
     TAILQ_FOREACH(current, &owindows, owindows) {
         DLOG("matching: %p / %s\n", current->con, current->con->name);
         int border_style = current->con->border_style;
-        char *end;
-        int tmp_border_width = -1;
-        tmp_border_width = strtol(border_width, &end, 10);
-        if (end == border_width) {
-            /* no valid digits found */
-            tmp_border_width = -1;
-        }
+        int con_border_width = border_width;
+
         if (strcmp(border_style_str, "toggle") == 0) {
             border_style++;
             border_style %= 3;
             if (border_style == BS_NORMAL)
-                tmp_border_width = 2;
+                con_border_width = 2;
             else if (border_style == BS_NONE)
-                tmp_border_width = 0;
+                con_border_width = 0;
             else if (border_style == BS_PIXEL)
-                tmp_border_width = 1;
+                con_border_width = 1;
         } else {
-            if (strcmp(border_style_str, "normal") == 0)
+            if (strcmp(border_style_str, "normal") == 0) {
                 border_style = BS_NORMAL;
-            else if (strcmp(border_style_str, "pixel") == 0)
+            } else if (strcmp(border_style_str, "pixel") == 0) {
                 border_style = BS_PIXEL;
-            else if (strcmp(border_style_str, "1pixel") == 0) {
+            else if (strcmp(border_style_str, "1pixel") == 0) {
                 border_style = BS_PIXEL;
-                tmp_border_width = 1;
-            } else if (strcmp(border_style_str, "none") == 0)
+                con_border_width = 1;
+            } else if (strcmp(border_style_str, "none") == 0) {
                 border_style = BS_NONE;
-            else {
+            else {
                 ELOG("BUG: called with border_style=%s\n", border_style_str);
                 ysuccess(false);
                 return;
             }
         }
-        con_set_border_style(current->con, border_style, tmp_border_width);
+
+        con_set_border_style(current->con, border_style, logical_px(con_border_width));
     }
 
     cmd_output->needs_tree_render = true;
@@ -911,10 +870,11 @@ void cmd_workspace(I3_CMD, const char *which) {
 }
 
 /*
- * Implementation of 'workspace number <name>'
+ * Implementation of 'workspace [--no-auto-back-and-forth] number <name>'
  *
  */
-void cmd_workspace_number(I3_CMD, const char *which) {
+void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
+    const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
     Con *output, *workspace = NULL;
 
     if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
@@ -942,7 +902,7 @@ void cmd_workspace_number(I3_CMD, const char *which) {
         cmd_output->needs_tree_render = true;
         return;
     }
-    if (maybe_back_and_forth(cmd_output, workspace->name))
+    if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, workspace->name))
         return;
     workspace_show(workspace);
 
@@ -970,10 +930,12 @@ void cmd_workspace_back_and_forth(I3_CMD) {
 }
 
 /*
- * Implementation of 'workspace <name>'
+ * Implementation of 'workspace [--no-auto-back-and-forth] <name>'
  *
  */
-void cmd_workspace_name(I3_CMD, const char *name) {
+void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
+    const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
+
     if (strncasecmp(name, "__", strlen("__")) == 0) {
         LOG("You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
         ysuccess(false);
@@ -987,7 +949,7 @@ void cmd_workspace_name(I3_CMD, const char *name) {
     }
 
     DLOG("should switch to workspace %s\n", name);
-    if (maybe_back_and_forth(cmd_output, name))
+    if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, name))
         return;
     workspace_show_by_name(name);
 
@@ -997,10 +959,10 @@ void cmd_workspace_name(I3_CMD, const char *name) {
 }
 
 /*
- * Implementation of 'mark [--toggle] <mark>'
+ * Implementation of 'mark [--add|--replace] [--toggle] <mark>'
  *
  */
-void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
+void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
     HANDLE_EMPTY_MATCH;
 
     owindow *current = TAILQ_FIRST(&owindows);
@@ -1016,10 +978,12 @@ void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
     }
 
     DLOG("matching: %p / %s\n", current->con, current->con->name);
+
+    mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
     if (toggle != NULL) {
-        con_mark_toggle(current->con, mark);
+        con_mark_toggle(current->con, mark, mark_mode);
     } else {
-        con_mark(current->con, mark);
+        con_mark(current->con, mark, mark_mode);
     }
 
     cmd_output->needs_tree_render = true;
@@ -1032,7 +996,14 @@ void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
  *
  */
 void cmd_unmark(I3_CMD, const char *mark) {
-    con_unmark(mark);
+    if (match_is_empty(current_match)) {
+        con_unmark(NULL, mark);
+    } else {
+        owindow *current;
+        TAILQ_FOREACH(current, &owindows, owindows) {
+            con_unmark(current->con, mark);
+        }
+    }
 
     cmd_output->needs_tree_render = true;
     // XXX: default reply for now, make this a better reply
@@ -1166,7 +1137,7 @@ void cmd_move_workspace_to_output(I3_CMD, const char *name) {
 }
 
 /*
- * Implementation of 'split v|h|vertical|horizontal'.
+ * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
  *
  */
 void cmd_split(I3_CMD, const char *direction) {
@@ -1180,6 +1151,24 @@ void cmd_split(I3_CMD, const char *direction) {
             continue;
         }
 
+        DLOG("matching: %p / %s\n", current->con, current->con->name);
+        if (direction[0] == 't') {
+            layout_t current_layout;
+            if (current->con->type == CT_WORKSPACE) {
+                current_layout = current->con->layout;
+            } else {
+                current_layout = current->con->parent->layout;
+            }
+            /* toggling split orientation */
+            if (current_layout == L_SPLITH) {
+                tree_split(current->con, VERT);
+            } else {
+                tree_split(current->con, HORIZ);
+            }
+        } else {
+            tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+        }
+
         DLOG("matching: %p / %s\n", current->con, current->con->name);
         tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
     }
@@ -1196,7 +1185,6 @@ void cmd_split(I3_CMD, const char *direction) {
 void cmd_kill(I3_CMD, const char *kill_mode_str) {
     if (kill_mode_str == NULL)
         kill_mode_str = "window";
-    owindow *current;
 
     DLOG("kill_mode=%s\n", kill_mode_str);
 
@@ -1211,14 +1199,11 @@ void cmd_kill(I3_CMD, const char *kill_mode_str) {
         return;
     }
 
-    /* check if the match is empty, not if the result is empty */
-    if (match_is_empty(current_match))
-        tree_close_con(kill_mode);
-    else {
-        TAILQ_FOREACH(current, &owindows, owindows) {
-            DLOG("matching: %p / %s\n", current->con, current->con->name);
-            tree_close(current->con, kill_mode, false, false);
-        }
+    HANDLE_EMPTY_MATCH;
+
+    owindow *current;
+    TAILQ_FOREACH(current, &owindows, owindows) {
+        con_close(current->con, kill_mode);
     }
 
     cmd_output->needs_tree_render = true;
@@ -1460,6 +1445,8 @@ void cmd_sticky(I3_CMD, const char *action) {
      * sure it gets pushed to the front now. */
     output_push_sticky_windows(focused);
 
+    ewmh_update_wm_desktop();
+
     cmd_output->needs_tree_render = true;
     ysuccess(true);
 }
@@ -1580,6 +1567,9 @@ void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
  */
 void cmd_exit(I3_CMD) {
     LOG("Exiting due to user command.\n");
+#ifdef I3_ASAN_ENABLED
+    __lsan_do_leak_check();
+#endif
     ipc_shutdown();
     unlink(config.ipc_socket_path);
     xcb_disconnect(conn);
@@ -1738,29 +1728,43 @@ void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y) {
  *
  */
 void cmd_move_window_to_center(I3_CMD, const char *method) {
-    if (!con_is_floating(focused)) {
-        ELOG("Cannot change position. The window/container is not floating\n");
-        yerror("Cannot change position. The window/container is not floating.");
-        return;
-    }
+    bool has_error = false;
+    HANDLE_EMPTY_MATCH;
 
-    if (strcmp(method, "absolute") == 0) {
-        DLOG("moving to absolute center\n");
-        floating_center(focused->parent, croot->rect);
+    owindow *current;
+    TAILQ_FOREACH(current, &owindows, owindows) {
+        Con *floating_con = con_inside_floating(current->con);
+        if (floating_con == NULL) {
+            ELOG("con %p / %s is not floating, cannot move it to the center.\n",
+                 current->con, current->con->name);
 
-        floating_maybe_reassign_ws(focused->parent);
-        cmd_output->needs_tree_render = true;
-    }
+            if (!has_error) {
+                yerror("Cannot change position of a window/container because it is not floating.");
+                has_error = true;
+            }
 
-    if (strcmp(method, "position") == 0) {
-        DLOG("moving to center\n");
-        floating_center(focused->parent, con_get_workspace(focused)->rect);
+            continue;
+        }
 
-        cmd_output->needs_tree_render = true;
+        if (strcmp(method, "absolute") == 0) {
+            DLOG("moving to absolute center\n");
+            floating_center(floating_con, croot->rect);
+
+            floating_maybe_reassign_ws(floating_con);
+            cmd_output->needs_tree_render = true;
+        }
+
+        if (strcmp(method, "position") == 0) {
+            DLOG("moving to center\n");
+            floating_center(floating_con, con_get_workspace(floating_con)->rect);
+
+            cmd_output->needs_tree_render = true;
+        }
     }
 
     // XXX: default reply for now, make this a better reply
-    ysuccess(true);
+    if (!has_error)
+        ysuccess(true);
 }
 
 /*
@@ -1839,27 +1843,33 @@ void cmd_title_format(I3_CMD, const char *format) {
 
     owindow *current;
     TAILQ_FOREACH(current, &owindows, owindows) {
-        if (current->con->window == NULL)
-            continue;
-
         DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
-        FREE(current->con->window->title_format);
+        FREE(current->con->title_format);
 
         /* If we only display the title without anything else, we can skip the parsing step,
          * so we remove the title format altogether. */
         if (strcasecmp(format, "%title") != 0) {
-            current->con->window->title_format = sstrdup(format);
+            current->con->title_format = sstrdup(format);
 
-            i3String *formatted_title = window_parse_title_format(current->con->window);
-            ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
-            I3STRING_FREE(formatted_title);
+            if (current->con->window != NULL) {
+                i3String *formatted_title = con_parse_title_format(current->con);
+                ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
+                I3STRING_FREE(formatted_title);
+            }
         } else {
-            /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
-            ewmh_update_visible_name(current->con->window->id, NULL);
+            if (current->con->window != NULL) {
+                /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
+                ewmh_update_visible_name(current->con->window->id, NULL);
+            }
         }
 
-        /* Make sure the window title is redrawn immediately. */
-        current->con->window->name_x_changed = true;
+        if (current->con->window != NULL) {
+            /* Make sure the window title is redrawn immediately. */
+            current->con->window->name_x_changed = true;
+        } else {
+            /* For windowless containers we also need to force the redrawing. */
+            FREE(current->con->deco_render_params);
+        }
     }
 
     cmd_output->needs_tree_render = true;
@@ -1902,12 +1912,16 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
     GREP_FIRST(check_dest, output_get_content(output),
                !strcasecmp(child->name, new_name));
 
-    if (check_dest != NULL) {
+    /* If check_dest == workspace, the user might be changing the case of the
+     * workspace, or it might just be a no-op. */
+    if (check_dest != NULL && check_dest != workspace) {
         yerror("New workspace \"%s\" already exists", new_name);
         return;
     }
 
     /* Change the name and try to parse it as a number. */
+    /* old_name might refer to workspace->name, so copy it before free()ing */
+    char *old_name_copy = sstrdup(old_name);
     FREE(workspace->name);
     workspace->name = sstrdup(new_name);
 
@@ -1948,7 +1962,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
     ewmh_update_desktop_viewport();
     ewmh_update_current_desktop();
 
-    startup_sequence_rename_workspace(old_name, new_name);
+    startup_sequence_rename_workspace(old_name_copy, new_name);
+    free(old_name_copy);
 }
 
 /*