From 4143734747b7b544daecdf1b8676838362c6cb59 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 19 Jul 2023 11:46:28 -0400 Subject: fix memory leaks (not really leaky) --- lsp-write.c | 7 +++++++ lsp.c | 1 + lsp.h | 2 ++ main.c | 1 + syntax.c | 8 ++++++++ ted.h | 2 ++ 6 files changed, 21 insertions(+) diff --git a/lsp-write.c b/lsp-write.c index 830c0ab..df695a6 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -680,3 +680,10 @@ void write_message(LSP *lsp, LSPMessage *message) { } #undef write_bool + +void lsp_write_quit(void) { + arr_foreach_ptr(language_ids, LanguageId, lid) { + free(lid->identifier); + } + arr_clear(language_ids); +} diff --git a/lsp.c b/lsp.c index c50ecc1..cac2bea 100644 --- a/lsp.c +++ b/lsp.c @@ -747,4 +747,5 @@ void lsp_quit(void) { SDL_DestroyMutex(request_id_mutex); request_id_mutex = NULL; } + lsp_write_quit(); } diff --git a/lsp.h b/lsp.h index dd7288f..fe74703 100644 --- a/lsp.h +++ b/lsp.h @@ -755,6 +755,8 @@ char *json_string_get_alloc(const JSON *json, JSONString string); void json_debug_print(const JSON *json); size_t json_escape_to(char *out, size_t out_sz, const char *in); char *json_escape(const char *str); +/// free resources used by lsp-write.c +void lsp_write_quit(void); /// print server-to-client communication #define LSP_SHOW_S2C 0 diff --git a/main.c b/main.c index 928fd98..2985f3c 100644 --- a/main.c +++ b/main.c @@ -1188,6 +1188,7 @@ int main(int argc, char **argv) { ted->lsps[i] = NULL; } lsp_quit(); + syntax_quit(); arr_foreach_ptr(ted->shell_history, char *, cmd) { free(*cmd); diff --git a/syntax.c b/syntax.c index 308f39e..87d83cd 100644 --- a/syntax.c +++ b/syntax.c @@ -2214,3 +2214,11 @@ void syntax_register_language(const LanguageInfo *info) { lsp_register_language(info->id, info->lsp_identifier); } + +void syntax_quit(void) { + arr_foreach_ptr(language_names, LanguageName, lname) { + free(lname->name); + } + arr_clear(language_names); + arr_clear(syntax_highlighters); +} diff --git a/ted.h b/ted.h index d67206f..ecd6e89 100644 --- a/ted.h +++ b/ted.h @@ -1603,6 +1603,8 @@ bool syntax_is_opening_bracket(Language lang, char32_t c); /// To highlight multiple lines, start out with a zeroed SyntaxState, and pass a pointer to it each time. /// You can set char_types to NULL if you just want to advance the state, and don't care about the character types. void syntax_highlight(SyntaxState *state, Language lang, const char32_t *line, u32 line_len, SyntaxCharType *char_types); +/// free up resources used by syntax.c +void syntax_quit(void); // === tags.c === void tags_generate(Ted *ted, bool run_in_build_window); -- cgit v1.2.3