summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-27 14:40:46 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-27 14:40:46 -0500
commita3c71115434018e16c5f3c2a4c3672ee3a12b7dc (patch)
treedb69dd57df1b1ee33b1d35500cfb4f5282e32700 /buffer.c
parent463183bdf4ca1637cf08b8e5dc441490e96c0ac0 (diff)
fixed some memory leaks
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c7
1 files changed, 6 insertions, 1 deletions
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);