From 3a2583e918bcc805fe860252f8a520fc2f9b26ce Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 18 Jul 2025 00:34:56 +0300 Subject: fixed minor memory leaks of per-state data in teco_machine_main_t * These were leaked e.g. in case of end-of-macro errors, but also in case of syntax highlighting (teco_lexer_style()). I considered to solve this by overwriting more of the end_of_macro_cb, but it didn't turn out to be trivial always. * Considering that the union in teco_machine_main_t saved only 3 machine words of memory, I decided to sacrifice those for more robust memory management. * teco_machine_qregspec_t cannot be directly embedded into teco_machine_main_t due to recursive dependencies with teco_machine_stringbuilding_t. It could now and should perhaps be allocated only once in teco_machine_main_init(), but it would require more refactoring. --- src/qreg-commands.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/qreg-commands.c') diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 7189771..9407e6c 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -39,8 +39,8 @@ teco_state_expectqreg_initial(teco_machine_main_t *ctx, GError **error) teco_state_t *current = ctx->parent.current; /* - * NOTE: We have to allocate a new instance always since `expectqreg` - * is part of an union. + * NOTE: This could theoretically be allocated once in + * teco_machine_main_init(), but we'd have to set the type here anyway. */ ctx->expectqreg = teco_machine_qregspec_new(current->expectqreg.type, ctx->qreg_table_locals, ctx->parent.must_undo); @@ -69,7 +69,7 @@ teco_state_expectqreg_input(teco_machine_main_t *ctx, gunichar chr, GError **err /* * NOTE: ctx->expectqreg is preserved since we may want to query it from follow-up - * states. This means, it must usually be stored manually in got_register_cb() via: + * states. This means, it must usually be reset manually in got_register_cb() via: * teco_state_expectqreg_reset(ctx); */ return current->expectqreg.got_register_cb(ctx, qreg, table, error); -- cgit v1.2.3