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/parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index ee705a0..33d2e7f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -81,7 +81,7 @@ teco_machine_input(teco_machine_t *ctx, gunichar chr, GError **error) gboolean teco_state_end_of_macro(teco_machine_t *ctx, GError **error) { - g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_SYNTAX, "Unterminated command"); return FALSE; } @@ -386,7 +386,8 @@ teco_machine_main_clear(teco_machine_main_t *ctx) teco_goto_table_clear(&ctx->goto_table); teco_string_clear(&ctx->expectstring.string); teco_machine_stringbuilding_clear(&ctx->expectstring.machine); - // FIXME: Could leak ctx->goto_label, but it's in an union + teco_string_clear(&ctx->goto_label); + teco_machine_qregspec_free(ctx->expectqreg); } /** Append string to result with case folding. */ @@ -1012,8 +1013,7 @@ teco_machine_stringbuilding_escape(teco_machine_stringbuilding_t *ctx, const gch void teco_machine_stringbuilding_clear(teco_machine_stringbuilding_t *ctx) { - if (ctx->machine_qregspec) - teco_machine_qregspec_free(ctx->machine_qregspec); + teco_machine_qregspec_free(ctx->machine_qregspec); teco_string_clear(&ctx->code); } -- cgit v1.2.3