groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 14/35: [groff]: Use single exit path, freeing memory.


From: G. Branden Robinson
Subject: [groff] 14/35: [groff]: Use single exit path, freeing memory.
Date: Tue, 21 Jun 2022 14:26:29 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 6769e56aab10f9d73f97cf719732420983b6cb81
Author: G. Branden Robinson <g.branden.robinson@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.robinson@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.robinson@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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]