From 73ff5a9561475deba3dc45d95554ca5daeaa086d Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 21 Mar 2020 09:30:57 +0000 Subject: [PATCH] more: use single exit path to ensure resource freeing is unified And be a little more complete all the allocations that can be released are, but there is a small catch. As mentioned in ncurses FAQ some leaks are intentional, and that's the way they are. Reference: https://invisible-island.net/ncurses/ncurses.faq.html#config_leaks Reference: http://man7.org/linux/man-pages/man3/_nc_free_tinfo.3x.html Signed-off-by: Sami Kerola --- text-utils/more.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/text-utils/more.c b/text-utils/more.c index dbcc2db019..a1b4df7af8 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -752,12 +752,14 @@ static void __attribute__((__noreturn__)) more_exit(struct more_control *ctl) } else if (!ctl->clear_line_ends && (ctl->prompt_len > 0)) { kill_line(ctl); fflush(stdout); - } else - fputc('\n', stderr); + } free(ctl->previous_search); free(ctl->shell_line); free(ctl->line_buf); free(ctl->go_home); + if (ctl->current_file) + fclose(ctl->current_file); + del_curterm(cur_term); _exit(EXIT_SUCCESS); } @@ -2079,9 +2081,7 @@ int main(int argc, char **argv) ctl.first_file = 0; ctl.argv_position++; } - free(ctl.previous_search); - free(initbuf); - free(ctl.line_buf); - reset_tty(&ctl); - exit(EXIT_SUCCESS); + ctl.clear_line_ends = 0; + ctl.prompt_len = 0; + more_exit(&ctl); } -- 2.47.2