]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
s390: s390_machine leak
authorJens Remus <jremus@linux.ibm.com>
Mon, 27 Jan 2025 15:43:39 +0000 (16:43 +0100)
committerJens Remus <jremus@linux.ibm.com>
Mon, 27 Jan 2025 15:43:39 +0000 (16:43 +0100)
commitc622993a154e6134b6dae0c31455e30cd96e4fa7
treefb8653e39172664c7ad06be49dc6ef4cb6f08d26
parent4bda1fb42f3ba7b06d38a9f8277c40ad37226a51
s390: s390_machine leak

Simplify the .machine directive parsing logic, so that cpu_string is
always xstrdup'd and can therefore always be xfree'd before returning
to the caller.

This resolves the following memory leak reported by ASAN:

Direct leak of 13 byte(s) in 3 object(s) allocated from:
    #0 0x3ff8aafbb1d in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x2aa338861cf in xmalloc ../../libiberty/xmalloc.c:149
    #2 0x2aa338868ff in xstrdup ../../libiberty/xstrdup.c:34
    #3 0x2aa320253cb in s390_machine ../../gas/config/tc-s390.c:2172
    #4 0x2aa31fddc7b in read_a_source_file ../../gas/read.c:1293
    #5 0x2aa31f4f7bf in perform_an_assembly_pass ../../gas/as.c:1223
    #6 0x2aa31f4f7bf in main ../../gas/as.c:1436
    #7 0x3ff8a02be35 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #8 0x3ff8a02bf33 in __libc_start_main_impl ../csu/libc-start.c:360
    #9 0x2aa31f5758f  (/home/jremus/git/binutils/build-asan/gas/as-new+0x2d5758f) (BuildId: ...)

While at it add tests with double quoted .machine
"<cpu>[+<extension>...]" values.

gas/
* config/tc-s390.c (s390_machine): Simplify parsing and free
cpu_string before returning.

gas/testsuite/
* gas/s390/machine-parsing-1.l: Add tests with double quoted
values.
* gas/s390/machine-parsing-1.s: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
gas/config/tc-s390.c
gas/testsuite/gas/s390/machine-parsing-1.l
gas/testsuite/gas/s390/machine-parsing-1.s