groff-commit
[Top][All Lists]
Advanced

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

[groff] 02/04: Stop mixing up heap storage management strategies.


From: G. Branden Robinson
Subject: [groff] 02/04: Stop mixing up heap storage management strategies.
Date: Thu, 22 Oct 2020 06:22:26 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 06ee2524421ae607d0310204e3ddaea790af2fd6
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Oct 22 21:03:09 2020 +1100

    Stop mixing up heap storage management strategies.
    
    ...in one respect, anyway.  A further audit would be good.
    
    Use only malloc() and free() to manage memory of paths opened by the
    parser instead of mixing in C++ new/delete management under some
    runtime-dependent circumstances.
    
    * src/libs/libgroff/relocate.cpp (relocatep): Use malloc(), not new.
    * src/roff/troff/input.cpp (process_macro_file, process_startup_file,
      macro_source): Use free(), not (a_)delete.
    
    Thanks to an anonymous contributor for the report and patch.
    
    Fixes <https://savannah.gnu.org/bugs/index.php?56694>.
---
 ChangeLog                      | 15 +++++++++++++++
 src/libs/libgroff/relocate.cpp | 10 ++++++++--
 src/roff/troff/input.cpp       |  6 +++---
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 754a795..1ae356b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2020-10-22  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       Use only malloc() and free() to manage memory of paths opened by
+       the parser instead of mixing in C++ new/delete management under
+       some runtime-dependent circumstances.
+
+       * src/libs/libgroff/relocate.cpp (relocatep): Use malloc(), not
+       new.
+       * src/roff/troff/input.cpp (process_macro_file,
+       process_startup_file, macro_source): Use free(), not (a_)delete.
+
+       Thanks to an anonymous contributor for the report and patch.
+
+       Fixes <https://savannah.gnu.org/bugs/index.php?56694>.
+
+2020-10-22  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * man/groff_char.7.man (Description/Special character escape
        forms): Clarify discussion of Unicode Normalization Form D and
        its applicability to code points acceptable in Unicode numeric
diff --git a/src/libs/libgroff/relocate.cpp b/src/libs/libgroff/relocate.cpp
index 4273e5a..8c973d9 100644
--- a/src/libs/libgroff/relocate.cpp
+++ b/src/libs/libgroff/relocate.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Provide relocation for macro and font files.
    Copyright (C) 2005-2018 Free Software Foundation, Inc.
 
@@ -211,7 +210,8 @@ char *relocatep(const char *path)
     return strsave(path);
   char *relative_path = (char *)path + INSTALLPATHLEN;
   size_t relative_path_len = strlen(relative_path);
-  char *relocated_path = new char[curr_prefix_len + relative_path_len + 1];
+  char *relocated_path = (char *)malloc(curr_prefix_len
+                                       + relative_path_len + 1);
   strcpy(relocated_path, curr_prefix);
   strcat(relocated_path, relative_path);
 #if DEBUG
@@ -234,3 +234,9 @@ char *relocate(const char *path)
 #endif
   return p;
 }
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index e3f3ab0..ccf5ac0 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7738,7 +7738,7 @@ static void process_macro_file(const char *mac)
   if (!fp)
     fatal("can't find macro file %1", mac);
   const char *s = symbol(path).contents();
-  a_delete path;
+  free(path);
   input_stack::push(new file_iterator(fp, s));
   tok.next();
   process_input_stack();
@@ -7752,7 +7752,7 @@ static void process_startup_file(const char *filename)
   FILE *fp = mac_path->open_file(filename, &path);
   if (fp) {
     input_stack::push(new file_iterator(fp, symbol(path).contents()));
-    a_delete path;
+    free(path);
     tok.next();
     process_input_stack();
   }
@@ -7795,7 +7795,7 @@ void macro_source()
     }
     if (fp) {
       input_stack::push(new file_iterator(fp, symbol(path).contents()));
-      a_delete path;
+      free(path);
     }
     else
       warning(WARN_FILE, "can't find macro file '%1'", nm.contents());



reply via email to

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