]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: use single exit path to ensure resource freeing is unified
authorSami Kerola <kerolasa@iki.fi>
Sat, 21 Mar 2020 09:30:57 +0000 (09:30 +0000)
committerSami Kerola <kerolasa@iki.fi>
Mon, 13 Apr 2020 11:13:51 +0000 (12:13 +0100)
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 <kerolasa@iki.fi>
text-utils/more.c

index dbcc2db0190ff49905452f8e38a4db14fc761b6b..a1b4df7af895cc4f138a2bd724caafebd772bc9d 100644 (file)
@@ -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);
 }