Bug 30322 - gdb memory leak
Summary: gdb memory leak
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 13.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 30504 30533 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-04-07 07:46 UTC by 陈孟达
Modified: 2023-06-09 20:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-04-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 陈孟达 2023-04-07 07:46:28 UTC
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).
```
Comment 1 Tom Tromey 2023-04-07 19:10:44 UTC
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.
Comment 2 Tom Tromey 2023-06-01 13:30:55 UTC
*** Bug 30504 has been marked as a duplicate of this bug. ***
Comment 3 Tom Tromey 2023-06-09 20:02:43 UTC
*** Bug 30533 has been marked as a duplicate of this bug. ***