gbranden pushed a commit to branch master in repository groff. commit 6769e56aab10f9d73f97cf719732420983b6cb81 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Mon Jun 20 11:15:09 2022 -0500
[groff]: Use single exit path, freeing memory. * src/roff/groff/groff.cpp: Use single exit path, freeing memory allocated for strings. (xexit): Add `exit()` wrapper; free allocated memory. (main): Use it in all three exit paths. --- ChangeLog | 7 +++++++ src/roff/groff/groff.cpp | 23 +++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3dcfa46..72c9e3e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2022-06-20 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/roff/groff/groff.cpp: Use single exit path, freeing + memory allocated for strings. + (xexit): Add `exit()` wrapper; free allocated memory. + (main): Use it in all three exit paths. + 2022-06-20 G. Branden Robinson <g.branden.robin...@gmail.com> * src/roff/groff/groff.cpp: Refactor to be more meticulous with diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp index 1ab80711..3556cb2f 100644 --- a/src/roff/groff/groff.cpp +++ b/src/roff/groff/groff.cpp @@ -128,6 +128,16 @@ static void xputenv(const char *s) { return; } +static void xexit(int status) { + free(spooler); + free(predriver); + free(postdriver); + free(saved_path); + free(groff_bin_path); + free(groff_font_path); + exit(status); +} + int main(int argc, char **argv) { program_name = argv[0]; @@ -349,7 +359,7 @@ int main(int argc, char **argv) break; case '?': usage(stderr); - exit(EXIT_FAILURE); + xexit(EXIT_FAILURE); break; default: assert(0 == "no case to handle option character"); @@ -517,15 +527,8 @@ int main(int argc, char **argv) if (Vflag) print_commands(Vflag == 1 ? stdout : stderr); if (Vflag == 1) - exit(EXIT_SUCCESS); - int status = run_commands(vflag); - free(spooler); - free(predriver); - free(postdriver); - free(saved_path); - free(groff_bin_path); - free(groff_font_path); - exit(status); + xexit(EXIT_SUCCESS); + xexit(run_commands(vflag)); } const char *xbasename(const char *s) _______________________________________________ Groff-commit mailing list Groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit