diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-18 00:34:56 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-18 00:34:56 +0300 |
commit | 3a2583e918bcc805fe860252f8a520fc2f9b26ce (patch) | |
tree | cfe2b7846df4e8c2d1572c6b7b961225a8e87487 /src/parser.h | |
parent | 4794367ce0c31f820bf2bd72d44c886984e3f7ed (diff) | |
download | sciteco-3a2583e918bcc805fe860252f8a520fc2f9b26ce.tar.gz |
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.
Diffstat (limited to 'src/parser.h')
-rw-r--r-- | src/parser.h | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/parser.h b/src/parser.h index 36a0302..a1583d2 100644 --- a/src/parser.h +++ b/src/parser.h @@ -514,17 +514,19 @@ struct teco_machine_main_t { /* * teco_state_t-dependent state. * - * Some of these cannot be used concurrently and are therefore - * grouped into unions. - * We could further optimize memory usage by dynamically allocating - * some of these structures on demand. + * Some cannot theoretically be used at the same time + * but it's hard to prevent memory leaks if putting them into + * a common union. */ - teco_machine_expectstring_t expectstring; - union { - teco_string_t goto_label; - teco_machine_qregspec_t *expectqreg; - teco_machine_scintilla_t scintilla; - }; + teco_machine_expectstring_t expectstring; + /** + * State machine for parsing Q-reg specifications. + * This could theoretically be inlined, but it would introduce + * a recursive dependency between qreg.h and parser.h. + */ + teco_machine_qregspec_t *expectqreg; + teco_string_t goto_label; + teco_machine_scintilla_t scintilla; }; typedef struct teco_machine_main_flags_t teco_machine_main_flags_t; |