public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] libctf: dump: fix small leak
@ 2024-07-31 20:45 Nick Alcock
  0 siblings, 0 replies; only message in thread
From: Nick Alcock @ 2024-07-31 20:45 UTC (permalink / raw)
  To: binutils-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4b04e01284f29a3d0e94fa0e0dd6a11be71c9a65

commit 4b04e01284f29a3d0e94fa0e0dd6a11be71c9a65
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Mon Jul 29 18:02:03 2024 +0100

    libctf: dump: fix small leak
    
    If you asprintf something and then use it only as input to another asprintf,
    it helps to free it afterwards.
    
    libctf/
            * ctf-dump.c (ctf_dump_header): Free the flagstr after use.
            (ctf_dump): Make a NULL return slightly clearer.

Diff:
---
 libctf/ctf-dump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index cd41996084d..a37d4b75d45 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -349,6 +349,7 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
 
       if (asprintf (&str, "Flags: 0x%x (%s)", fp->ctf_openflags, flagstr) < 0)
 	goto err;
+      free (flagstr);
       ctf_dump_append (state, str);
     }
 
@@ -814,7 +815,7 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
       if (!str)
 	{
 	  ctf_set_errno (fp, ENOMEM);
-	  return str;
+	  return NULL;
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-07-31 20:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-31 20:45 [binutils-gdb] libctf: dump: fix small leak Nick Alcock

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).