From 7413b9cab2690f7bed6d82e903b0fc08b1590360 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 15 Oct 2024 20:02:50 +0300 Subject: fixed memory leak when replacing command lines * this would also leak a few bytes on every of fnkeys.tes' movement commands --- src/cmdline.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index 232fb19..816816c 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -86,7 +86,7 @@ static gboolean teco_cmdline_insert(const gchar *data, gsize len, GError **error) { const teco_string_t src = {(gchar *)data, len}; - teco_string_t old_cmdline = {NULL, 0}; + g_auto(teco_string_t) old_cmdline = {NULL, 0}; gsize repl_pc = 0; teco_cmdline.machine.macro_pc = teco_cmdline.pc = teco_cmdline.effective_len; @@ -110,8 +110,6 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) /* * Parse/execute characters, one at a time so * undo tokens get emitted for the corresponding characters. - * - * FIXME: The inner loop should be factored out. */ while (teco_cmdline.pc < teco_cmdline.effective_len) { g_autoptr(GError) tmp_error = NULL; @@ -162,6 +160,7 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) teco_string_clear(&teco_cmdline.str); teco_cmdline.str = old_cmdline; + memset(&old_cmdline, 0, sizeof(old_cmdline)); teco_cmdline.machine.macro_pc = teco_cmdline.pc = repl_pc; /* rubout cmdline replacement command */ -- cgit v1.2.3