summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-08 11:48:19 -0500
committerpommicket <pommicket@gmail.com>2023-01-08 11:48:19 -0500
commit34212b559d7bb0eb0d4e7797ba3e9b1a718cedac (patch)
treec0d51adcde6c93adc340ae1b9a6cc4fd721c49cc
parent21c2b2244e4abddd70b9e1ee298dfe4b7a6d6d2d (diff)
fix memory leaks
-rw-r--r--build.c1
-rw-r--r--ide-autocomplete.c1
-rw-r--r--lsp.c16
-rw-r--r--main.c2
-rw-r--r--valgrind_suppresions.txt7
5 files changed, 13 insertions, 14 deletions
diff --git a/build.c b/build.c
index 93b6643..0adf0af 100644
--- a/build.c
+++ b/build.c
@@ -233,6 +233,7 @@ void build_check_for_errors(Ted *ted) {
.build_output_line = line_idx
};
arr_add(ted->build_errors, error);
+ free(filename);
}
}
}
diff --git a/ide-autocomplete.c b/ide-autocomplete.c
index f2382cb..6d5716b 100644
--- a/ide-autocomplete.c
+++ b/ide-autocomplete.c
@@ -340,6 +340,7 @@ void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *response) {
return;
}
+ autocomplete_clear_completions(ac);
arr_set_len(ac->completions, ncompletions);
for (size_t i = 0; i < ncompletions; ++i) {
const LSPCompletionItem *lsp_completion = &completion->items[i];
diff --git a/lsp.c b/lsp.c
index dde58d6..fe122a0 100644
--- a/lsp.c
+++ b/lsp.c
@@ -6,18 +6,11 @@
const char *language_to_str(Language language);
-static LSPMutex id_mutex;
-
// it's nice to have request IDs be totally unique, including across LSP servers.
static LSPRequestID get_request_id(void) {
// it's important that this never returns 0, since that's reserved for "no ID"
- static LSPRequestID last_request_id;
- LSPRequestID id = 0;
- assert(id_mutex);
- SDL_LockMutex(id_mutex);
- id = ++last_request_id;
- SDL_UnlockMutex(id_mutex);
- return id;
+ static _Atomic LSPRequestID last_request_id;
+ return ++last_request_id;
}
bool lsp_get_error(LSP *lsp, char *error, size_t error_size, bool clear) {
@@ -503,10 +496,7 @@ const char *lsp_document_path(LSP *lsp, LSPDocumentID document) {
LSP *lsp_create(const char *root_dir, const char *command, const char *configuration, FILE *log) {
LSP *lsp = calloc(1, sizeof *lsp);
if (!lsp) return NULL;
-
- if (!id_mutex)
- id_mutex = SDL_CreateMutex();
-
+
static LSPID curr_id = 1;
lsp->id = curr_id++;
lsp->log = log;
diff --git a/main.c b/main.c
index 4bacfb4..a440585 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,8 @@
/*
@TODO:
-- run everything through valgrind ideally with leak checking
- some way of opening + closing all C files in directory for clangd
textDocument/references to work?
+ - does adding compile_commands.json help?
- maybe it can be done with the clangd config instead.
- does vscode have the same problem?
- rust-analyzer bug reports:
diff --git a/valgrind_suppresions.txt b/valgrind_suppresions.txt
index 388ace8..af09ee7 100644
--- a/valgrind_suppresions.txt
+++ b/valgrind_suppresions.txt
@@ -55,6 +55,13 @@
...
}
{
+ nvidia_driver
+ Memcheck:Leak
+ ...
+ obj:/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.*
+ ...
+}
+{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable