diff options
-rw-r--r-- | src/cli/main.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/cli/main.c b/src/cli/main.c index cbecf50..ae84837 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -109,7 +109,8 @@ static void run_file(SandState *S, const char *filename) { static void repl(SandState *S) { char *line = NULL; - size_t line_length = 0; + size_t line_capacity = 0; + ssize_t line_length = 0; unsigned prompt_nr = 1; @@ -118,7 +119,7 @@ static void repl(SandState *S) { fflush(stdout); // At this point the memory at `line` is reused, invalidating all existing references. - if (getline(&line, &line_length, stdin) < 0) { + if ((line_length = getline(&line, &line_capacity, stdin)) < 0) { fputc('\n', stdout); break; // No more input - leave REPL loop. } @@ -130,6 +131,8 @@ static void repl(SandState *S) { sand_interpret(S, filename, line, line_length); } + + free(line); } static void print_help(FILE *stream, const char *argv0) { |