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;