From: Vadim Zhestikov Date: Sat, 1 Jul 2023 02:49:46 +0000 (-0700) Subject: Improved interactive shell. X-Git-Tag: 0.8.0~4 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=f2d3f14d0665e7fc1b297a5dbb8dab61b49282ac;p=njs.git Improved interactive shell. --- diff --git a/external/njs_shell.c b/external/njs_shell.c index d3aec088..e8b221d2 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -1073,19 +1073,24 @@ njs_cb_line_handler(char *line_in) njs_int_t ret; njs_str_t line; - if (line_in == NULL || strcmp(line_in, ".exit") == 0) { + if (line_in == NULL) { njs_running = NJS_DONE; return; } - njs_sigint_count = 0; - line.start = (u_char *) line_in; line.length = njs_strlen(line.start); + if (strcmp(line_in, ".exit") == 0) { + njs_running = NJS_DONE; + goto free_line; + } + + njs_sigint_count = 0; + if (line.length == 0) { rl_callback_handler_install(">> ", njs_cb_line_handler); - return; + goto free_line; } add_history((char *) line.start); @@ -1099,6 +1104,8 @@ njs_cb_line_handler(char *line_in) rl_callback_handler_install(">> ", njs_cb_line_handler); } +free_line: + free(line.start); }