gbranden pushed a commit to branch master
in repository groff.

commit 49a27412d6e12a8219a125193f2d13fa2d044164
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Jun 27 19:58:44 2022 -0500

    src/preproc/html/pre-html.cpp (cleanup): Add.
    
    * src/preproc/html/pre-html.cpp (cleanup): Add function to tidy
      memory before exiting.
    
      (main): Register aforementioned function with `atexit()`.  Die if
      registration fails.
---
 ChangeLog                     | 7 +++++++
 src/preproc/html/pre-html.cpp | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 5ea1418e..b8fa8ef2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2022-06-28  G. Branden Robinson <[email protected]>
 
+       * src/preproc/html/pre-html.cpp (cleanup): Add function to tidy
+       memory before exiting.
+       (main): Register aforementioned function with `atexit()`.  Die
+       if registration fails.
+
+2022-06-27  G. Branden Robinson <[email protected]>
+
        * src/preproc/html/pre-html.cpp (do_file): Die if `fclose()`
        fails; such a situation suggests a pretty hosed environment.
 
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index 3cd7b2ff..0c4bb4af 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -1742,6 +1742,11 @@ static bool do_file(const char *filename)
   return true;
 }
 
+static void cleanup(void)
+{
+  free(const_cast<char *>(image_gen));
+}
+
 int main(int argc, char **argv)
 {
 #ifdef CAPTURE_MODE
@@ -1757,6 +1762,8 @@ int main(int argc, char **argv)
   exit(EXIT_FAILURE);
 #endif /* CAPTURE_MODE */
   program_name = argv[0];
+  if (atexit(&cleanup) != 0)
+    sys_fatal("atexit");
   int operand_index = scanArguments(argc, argv);
   image_gen = strsave(get_image_generator());
   if (0 == image_gen)

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to