gbranden pushed a commit to branch master
in repository groff.

commit 0c42ba5c0f2ceeb1df975c294ae643da28a5679f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Apr 10 02:54:00 2026 -0500

    [troff]: `rhw` now frees memory allocated by `hw`.
    
    * src/roff/troff/env.cpp (remove_hyphenation_exception_words_request):
      Free the heap storage backing a hyphenation exception word when
      removing one--specifically, this is its list of hyphenation break
      points expressed as integers representing character positions in the
      word, allocated by `add_hyphenation_exception_words_request()`.
      Fastidiously assign null pointer literal to `word` local addressing
      that memory afterwards.
---
 ChangeLog              | 11 +++++++++++
 src/roff/troff/env.cpp | 10 ++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5994fdd52..38d2d40bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2026-04-10  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.cpp
+       (remove_hyphenation_exception_words_request): Free the heap
+       storage backing a hyphenation exception word when removing
+       one--specifically, this is its list of hyphenation break points
+       expressed as integers representing character positions in the
+       word, allocated by `add_hyphenation_exception_words_request()`.
+       Fastidiously assign null pointer literal to `word` local
+       addressing that memory afterwards.
+
 2026-04-10  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp: Rationalize header file inclusions,
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 23059e624..27ae627b3 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -4024,6 +4024,7 @@ static void remove_hyphenation_exception_words_request() 
// .rhw
   }
   dictionary_iterator iter(current_language->exceptions);
   symbol entry;
+  unsigned char *word = 0 /* nullptr */;
   if (!has_arg()) {
     while (iter.get(&entry, 0 /* nullptr */)) {
       assert(!entry.is_null());
@@ -4032,8 +4033,13 @@ static void remove_hyphenation_exception_words_request() 
// .rhw
       // fixing without also migrating to an STL unordered_map or
       // similar, and using a `struct` with a string and a `bool` in it
       // as the values.
-      if (strchr(entry.contents(), ' ') == 0 /* nullptr */)
-       current_language->exceptions.remove(entry.contents());
+      if (!entry.contains(' ')) {
+        word = static_cast<unsigned char *>(
+           current_language->exceptions.remove(entry.contents()));
+       assert(word != 0 /* nullptr */);
+       delete[] word;
+       word = 0 /* nullptr */;
+      }
     }
   }
   // TODO: Else read each argument as a word, normalize any hyphens

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

Reply via email to