From 0d69f89e6bedb5ef675610d1025eaf8b46bd3422 Mon Sep 17 00:00:00 2001 From: cflip Date: Thu, 12 Jan 2023 16:35:44 -0700 Subject: Clean up editor_state's memory on teardown --- editor.c | 8 ++++++++ editor.h | 2 ++ main.c | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/editor.c b/editor.c index ade6a77..9f51188 100644 --- a/editor.c +++ b/editor.c @@ -331,3 +331,11 @@ void editor_draw_message_bar(struct editor_state* editor, struct append_buffer* if (message_length && time(NULL) - editor->status_message_time < 5) ab_append(buffer, editor->status_message, message_length); } + +void editor_destroy(struct editor_state *editor) +{ + free(editor->filename); + for (int i = 0; i < editor->row_count; i++) + free_row(&editor->rows[i]); + free(editor->rows); +} diff --git a/editor.h b/editor.h index 7df152a..dc0b354 100644 --- a/editor.h +++ b/editor.h @@ -46,4 +46,6 @@ void editor_draw_rows(struct editor_state* editor, struct append_buffer* buffer) void editor_draw_status_bar(struct editor_state* editor, struct append_buffer* buffer); void editor_draw_message_bar(struct editor_state* editor, struct append_buffer* buffer); +void editor_destroy(struct editor_state *editor); + #endif diff --git a/main.c b/main.c index e3a9399..205d580 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,3 @@ -#include "input.h" #include "file.h" #include "editor.h" #include "window.h" @@ -23,5 +22,7 @@ int main(int argc, char** argv) } window_destroy(); + editor_destroy(&editor); + return 0; } -- cgit v1.2.3