* [binutils-gdb] gas: Fix memory leaks in ginsn.c
@ 2024-04-11 11:10 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2024-04-11 11:10 UTC (permalink / raw)
To: binutils-cvs
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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-04-11 11:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 11:10 [binutils-gdb] gas: Fix memory leaks in ginsn.c H.J. Lu
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).