From a3c71115434018e16c5f3c2a4c3672ee3a12b7dc Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 27 Dec 2020 14:40:46 -0500 Subject: fixed some memory leaks --- buffer.c | 7 ++++++- valgrind_suppresions.txt | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index 8cf2760..308c12d 100644 --- a/buffer.c +++ b/buffer.c @@ -377,6 +377,7 @@ static void buffer_remove_last_edit_if_empty(TextBuffer *buffer) { if (buffer->store_undo_events) { BufferEdit *last_edit = arr_lastp(buffer->undo_history); if (last_edit && !buffer_edit_does_anything(buffer, last_edit)) { + buffer_edit_free(last_edit); arr_remove_last(buffer->undo_history); } } @@ -435,7 +436,6 @@ static void buffer_line_free(Line *line) { // Does not free the pointer `buffer` (buffer might not have even been allocated with malloc) void buffer_free(TextBuffer *buffer) { - Line *lines = buffer->lines; u32 nlines = buffer->nlines; for (u32 i = 0; i < nlines; ++i) { @@ -443,6 +443,11 @@ void buffer_free(TextBuffer *buffer) { } free(lines); + arr_foreach_ptr(buffer->undo_history, BufferEdit, edit) + buffer_edit_free(edit); + arr_foreach_ptr(buffer->redo_history, BufferEdit, edit) + buffer_edit_free(edit); + arr_free(buffer->undo_history); arr_free(buffer->redo_history); diff --git a/valgrind_suppresions.txt b/valgrind_suppresions.txt index 3a6bc8d..45424fb 100644 --- a/valgrind_suppresions.txt +++ b/valgrind_suppresions.txt @@ -1,3 +1,10 @@ +{ + + Memcheck:Leak + ... + fun:_dbus_strdup + ... +} { Memcheck:Addr8 -- cgit v1.2.3