From: Jens Remus <jremus@linux.ibm.com>
To: binutils@sourceware.org, Andreas Krebbel <krebbel@linux.ibm.com>
Cc: Jens Remus <jremus@linux.ibm.com>
Subject: [PATCH 2/2] s390: s390_machine leak
Date: Wed, 22 Jan 2025 14:39:32 +0100 [thread overview]
Message-ID: <20250122133932.3728429-3-jremus@linux.ibm.com> (raw)
In-Reply-To: <20250122133932.3728429-1-jremus@linux.ibm.com>
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 | 38 ++++++++--------------
gas/testsuite/gas/s390/machine-parsing-1.l | 3 +-
gas/testsuite/gas/s390/machine-parsing-1.s | 3 ++
3 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index 113b9f41a1ec..b651acc3cf90 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -2146,32 +2146,21 @@ s390_machine (int ignore ATTRIBUTE_UNUSED)
SKIP_WHITESPACE ();
- if (*input_line_pointer == '"')
- {
- int len;
- cpu_string = demand_copy_C_string (&len);
- }
- else
- {
- char c;
-
- cpu_string = input_line_pointer;
- do
- {
- char * str;
+ {
+ char c;
- c = get_symbol_name (&str);
- c = restore_line_pointer (c);
- if (c == '+')
- ++ input_line_pointer;
- }
- while (c == '+');
+ c = get_symbol_name (&cpu_string);
+ while (c == '+')
+ {
+ char *str;
- c = *input_line_pointer;
- *input_line_pointer = 0;
- cpu_string = xstrdup (cpu_string);
- (void) restore_line_pointer (c);
- }
+ c = restore_line_pointer (c);
+ input_line_pointer++;
+ c = get_symbol_name (&str);
+ }
+ cpu_string = xstrdup (cpu_string);
+ (void) restore_line_pointer (c);
+ }
if (cpu_string != NULL)
{
@@ -2217,6 +2206,7 @@ s390_machine (int ignore ATTRIBUTE_UNUSED)
}
}
+ xfree (cpu_string);
demand_empty_rest_of_line ();
}
diff --git a/gas/testsuite/gas/s390/machine-parsing-1.l b/gas/testsuite/gas/s390/machine-parsing-1.l
index 1a83ec81897d..8850eff54320 100644
--- a/gas/testsuite/gas/s390/machine-parsing-1.l
+++ b/gas/testsuite/gas/s390/machine-parsing-1.l
@@ -1,2 +1,3 @@
.*: Assembler messages:
-.*:5: Error: invalid machine .foo.*
+.*:7: Error: invalid machine .foo.*
+.*:8: Error: invalid machine .foo.*
diff --git a/gas/testsuite/gas/s390/machine-parsing-1.s b/gas/testsuite/gas/s390/machine-parsing-1.s
index ea402bca793f..aa2a206a5fc1 100644
--- a/gas/testsuite/gas/s390/machine-parsing-1.s
+++ b/gas/testsuite/gas/s390/machine-parsing-1.s
@@ -1,5 +1,8 @@
.text
foo:
.machine z13
+ .machine "z13"
.machine z13+vx+novx+htm+nohtm+vx+novx+htm+nohtm
+ .machine "z13+vx+novx+htm+nohtm+vx+novx+htm+nohtm"
.machine foo
+ .machine "foo"
--
2.45.2
next prev parent reply other threads:[~2025-01-22 13:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 13:39 [PATCH 0/2] s390: Fix memory leaks in assembler and linker Jens Remus
2025-01-22 13:39 ` [PATCH 1/2] s390: s390_machinemode leak Jens Remus
2025-01-22 13:39 ` Jens Remus [this message]
2025-01-27 7:38 ` [PATCH 0/2] s390: Fix memory leaks in assembler and linker Andreas Krebbel
2025-01-27 15:46 ` Jens Remus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250122133932.3728429-3-jremus@linux.ibm.com \
--to=jremus@linux.ibm.com \
--cc=binutils@sourceware.org \
--cc=krebbel@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).