aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-15 20:02:50 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-15 20:02:50 +0300
commit7413b9cab2690f7bed6d82e903b0fc08b1590360 (patch)
tree975fa715fbd211e4e4d7b8c1ba5429f3c510992c
parent95dca302011d49e465a1ee50f722684969e49781 (diff)
downloadsciteco-7413b9cab2690f7bed6d82e903b0fc08b1590360.tar.gz
fixed memory leak when replacing command lines
* this would also leak a few bytes on every of fnkeys.tes' movement commands
-rw-r--r--src/cmdline.c5
1 files changed, 2 insertions, 3 deletions
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 */