gbranden pushed a commit to branch master
in repository groff.

commit 36b1672086ba968676d15555a51d8e4a6f6f26c6
Author: Bruno Haible <[email protected]>
AuthorDate: Sun Aug 2 13:54:48 2026 +0200

    pic: Fix undefined behaviour, part 1.
    
    This change fixes this ASAN finding:
    
    ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete 
[]) on 0x76fae07e0330
        #0 0x56401fe1d9ed in operator delete[](void*) 
/home/runner/work/llvm-project/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:179:46
        #1 0x56401fe67b0f in output::~output() 
/devel/groff/src/preproc/pic/object.cpp:47:3
        #2 0x56401fea35a4 in common_output::~common_output() 
/devel/groff/src/preproc/pic/common.h:20:7
        #3 0x56401feab614 in simple_output::~simple_output() 
/devel/groff/src/preproc/pic/troff.cpp:37:7
        #4 0x56401fea657a in troff_output::~troff_output() 
/devel/groff/src/preproc/pic/troff.cpp:276:1
        #5 0x56401fea65d4 in troff_output::~troff_output() 
/devel/groff/src/preproc/pic/troff.cpp:274:1
        #6 0x56401fe67423 in main /devel/groff/src/preproc/pic/main.cpp:698:3
    
    0x76fae07e0330 is located 0 bytes inside of 7-byte region 
[0x76fae07e0330,0x76fae07e0337)
    allocated by thread T0 here:
        #0 0x56401fdd9ee4 in malloc 
/home/runner/work/llvm-project/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:67:3
        #1 0x56401febb677 in strsave(char const*) 
/devel/groff/src/libs/libgroff/strsave.cpp:36:33
        #2 0x56401fe67d41 in output::set_args(char const*) 
/devel/groff/src/preproc/pic/object.cpp:62:12
        #3 0x56401fe66356 in do_picture(_IO_FILE*) 
/devel/groff/src/preproc/pic/main.cpp:297:10
        #4 0x56401fe64f4f in do_file(char const*) 
/devel/groff/src/preproc/pic/main.cpp:395:2
        #5 0x56401fe67241 in main /devel/groff/src/preproc/pic/main.cpp:691:7
    
    SUMMARY: AddressSanitizer: alloc-dealloc-mismatch 
/devel/groff/src/preproc/pic/object.cpp:47:3 in output::~output()
    
    * src/preproc/pic/object.cpp (output::~output, output::set_args): Free the
    args field using free(), not delete[].
---
 src/preproc/pic/object.cpp | 4 ++--
 src/preproc/pic/output.h   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index 7e8102764..32255a850 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -44,7 +44,7 @@ output::output() : args(0), desired_height(0.0), 
desired_width(0.0)
 
 output::~output()
 {
-  delete[] args;
+  free(args);
 }
 
 void output::set_desired_width_height(double wid, double ht)
@@ -55,7 +55,7 @@ void output::set_desired_width_height(double wid, double ht)
 
 void output::set_args(const char *s)
 {
-  delete[] args;
+  free(args);
   if (s == 0 || *s == '\0')
     args = 0;
   else
diff --git a/src/preproc/pic/output.h b/src/preproc/pic/output.h
index fbb72640b..3386c174d 100644
--- a/src/preproc/pic/output.h
+++ b/src/preproc/pic/output.h
@@ -30,7 +30,7 @@ struct line_type {
 
 class output {
 protected:
-  char *args;
+  char *args;                  // to be freed with free()
   double desired_height;       // zero if no height specified
   double desired_width;                // zero if no depth specified
   double compute_scale(double, const position &, const position &);

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

Reply via email to