From: H.J. Lu <hjl@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] gas: Fix memory leaks in ginsn.c
Date: Thu, 11 Apr 2024 11:10:45 +0000 (GMT) [thread overview]
Message-ID: <20240411111046.01C9A3858C52@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=80ec23548f144e7bdfe2e7e9bcf78279c100d1ee
commit 80ec23548f144e7bdfe2e7e9bcf78279c100d1ee
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Apr 9 16:05:18 2024 -0700
gas: Fix memory leaks in ginsn.c
Free buffer memory after use in ginsn.c.
* ginsn.c (ginsn_dst_print): Free buffer after use.
(ginsn_print): Likewise.
Diff:
---
gas/ginsn.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/gas/ginsn.c b/gas/ginsn.c
index be06324f1f1..b60b2e542ac 100644
--- a/gas/ginsn.c
+++ b/gas/ginsn.c
@@ -507,6 +507,7 @@ ginsn_dst_print (struct ginsn_dst *dst)
char *buf = XNEWVEC (char, 32);
sprintf (buf, "%%r%d", ginsn_get_dst_reg (dst));
strcat (dst_str, buf);
+ free (buf);
}
else if (dst->type == GINSN_DST_INDIRECT)
{
@@ -514,6 +515,7 @@ ginsn_dst_print (struct ginsn_dst *dst)
sprintf (buf, "[%%r%d+%lld]", ginsn_get_dst_reg (dst),
(long long int) ginsn_get_dst_disp (dst));
strcat (dst_str, buf);
+ free (buf);
}
gas_assert (strlen (dst_str) < GINSN_LISTING_OPND_LEN);
@@ -570,20 +572,26 @@ ginsn_print (ginsnS *ginsn)
/* src 1. */
src = ginsn_get_src1 (ginsn);
+ char *src_buf = ginsn_src_print (src);
str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
- " %s", ginsn_src_print (src));
+ " %s", src_buf);
+ free (src_buf);
gas_assert (str_size >= 0 && str_size < GINSN_LISTING_LEN);
/* src 2. */
src = ginsn_get_src2 (ginsn);
+ src_buf = ginsn_src_print (src);
str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
- "%s", ginsn_src_print (src));
+ "%s", src_buf);
+ free (src_buf);
gas_assert (str_size >= 0 && str_size < GINSN_LISTING_LEN);
/* dst. */
dst = ginsn_get_dst (ginsn);
+ char *dst_buf = ginsn_dst_print (dst);
str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
- "%s", ginsn_dst_print (dst));
+ "%s", dst_buf);
+ free (dst_buf);
end:
gas_assert (str_size >= 0 && str_size < GINSN_LISTING_LEN);
reply other threads:[~2024-04-11 11:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240411111046.01C9A3858C52@sourceware.org \
--to=hjl@sourceware.org \
--cc=binutils-cvs@sourceware.org \
/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).