fix: move ownership of line to oldline
- set line to null when moved - also, free line when loading from history
This commit is contained in:
@@ -357,6 +357,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldline = line;
|
oldline = line;
|
||||||
|
line = NULL;
|
||||||
}
|
}
|
||||||
} else if (ansi == ANSI_CURSOR_DOWN && historyoffset > 0) {
|
} else if (ansi == ANSI_CURSOR_DOWN && historyoffset > 0) {
|
||||||
historyoffset--;
|
historyoffset--;
|
||||||
@@ -383,6 +384,11 @@ int main(int argc, char** argv) {
|
|||||||
if (load_from_hist == 1) {
|
if (load_from_hist == 1) {
|
||||||
char* historyline = history[historyi - (historyoffset)];
|
char* historyline = history[historyi - (historyoffset)];
|
||||||
size_t historylinelen = strlen(historyline);
|
size_t historylinelen = strlen(historyline);
|
||||||
|
|
||||||
|
if (line != NULL) {
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
line = malloc(historylinelen + 1);
|
line = malloc(historylinelen + 1);
|
||||||
if (line == NULL) {
|
if (line == NULL) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user