I found a memory leak bug in gdb. Please confirm. Thanks! ### Test Environment Ubuntu 20.04, 64 bit binutils (version: v13.1 ;master) ### How to trigger Compile the program with AddressSanitizer Run command $ touch utils.o $ touch aaa $ mkdir dir $ touch core.357036 $ ./gdb --cd=dir/ --se=utils.o --core=core.357036 --exec=./aaa --pid=1680 --symbols=utils.o ### Details ASAN report $./gdb --cd=dir/ --se=utils.o --core=core.357036 --exec=./aaa --pid=1680 --symbols=utils.o ``` warning: Found custom handler for signal 7 (Bus error) preinstalled. warning: Found custom handler for signal 8 (Floating point exception) preinstalled. warning: Found custom handler for signal 11 (Segmentation fault) preinstalled. warning: Found custom handler for signal 15 (Terminated) preinstalled. Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN) won't be propagated to spawned programs. GNU gdb (GDB) 13.0.50.20220805-git Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... ./aaa: No such file or directory. utils.o: No such file or directory. Can't attach to process and specify a core file at the same time. ================================================================= ==2012456==ERROR: LeakSanitizer: detected memory leaks Direct leak of 112 byte(s) in 1 object(s) allocated from: #0 0x4e242d in operator new(unsigned long) (/home/cmd/lengthFuzz/binutils/gdb/gdb_cd_se_c_e_p_s/gdb+0x4e242d) #1 0x1de9fa6 in ui::ui(_IO_FILE*, _IO_FILE*, _IO_FILE*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/top.c:313:19 #2 0x15bec8b in captured_main_1(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:676:17 #3 0x15be28d in captured_main(void*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1319:3 #4 0x15be058 in gdb_main(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1344:7 #5 0x4e4f12 in main /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/gdb.c:32:10 #6 0x7f7aecdff082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16 Direct leak of 52 byte(s) in 1 object(s) allocated from: #0 0x4b0963 in __interceptor_realloc (/home/cmd/lengthFuzz/binutils/gdb/gdb_cd_se_c_e_p_s/gdb+0x4b0963) #1 0x7f7aeceea077 in getcwd /build/glibc-SzIz7B/glibc-2.31/io/../sysdeps/unix/sysv/linux/getcwd.c:84:8 Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x4e242d in operator new(unsigned long) (/home/cmd/lengthFuzz/binutils/gdb/gdb_cd_se_c_e_p_s/gdb+0x4e242d) #1 0x1dea176 in ui::ui(_IO_FILE*, _IO_FILE*, _IO_FILE*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/top.c:315:19 #2 0x15bec8b in captured_main_1(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:676:17 #3 0x15be28d in captured_main(void*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1319:3 #4 0x15be058 in gdb_main(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1344:7 #5 0x4e4f12 in main /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/gdb.c:32:10 #6 0x7f7aecdff082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16 Indirect leak of 48 byte(s) in 1 object(s) allocated from: #0 0x4e242d in operator new(unsigned long) (/home/cmd/lengthFuzz/binutils/gdb/gdb_cd_se_c_e_p_s/gdb+0x4e242d) #1 0x1de9fc1 in ui::ui(_IO_FILE*, _IO_FILE*, _IO_FILE*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/top.c:313:35 #2 0x15bec8b in captured_main_1(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:676:17 #3 0x15be28d in captured_main(void*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1319:3 #4 0x15be058 in gdb_main(captured_main_args*) /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/main.c:1344:7 #5 0x4e4f12 in main /home/cmd/FuzzDateset/binutils/binutils-gdb-binutils-2_39/gdb/gdb.c:32:10 #6 0x7f7aecdff082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16 SUMMARY: AddressSanitizer: 260 byte(s) leaked in 4 allocation(s). ```
I think that 'ui' leak is known and kind of a pain to get rid of. Not sure but maybe my unfinished rewrite of the redirection code fixes it.
*** Bug 30504 has been marked as a duplicate of this bug. ***
*** Bug 30533 has been marked as a duplicate of this bug. ***