From cfe3d40fc6394dae162f03acdd5a814bc7a47ef0 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Oct 2026 21:09:18 +0200 Subject: [PATCH] fix: move ownership of line to oldline - set line to null when moved - also, free line when loading from history --- src/msh.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/msh.c b/src/msh.c index 9d8490a..3139531 100644 --- a/src/msh.c +++ b/src/msh.c @@ -357,6 +357,7 @@ int main(int argc, char** argv) { } oldline = line; + line = NULL; } } else if (ansi == ANSI_CURSOR_DOWN && historyoffset > 0) { historyoffset--; @@ -383,6 +384,11 @@ int main(int argc, char** argv) { if (load_from_hist == 1) { char* historyline = history[historyi - (historyoffset)]; size_t historylinelen = strlen(historyline); + + if (line != NULL) { + free(line); + } + line = malloc(historylinelen + 1); if (line == NULL) { retval = 1;