[09/10] libctf: free ctf_dynsyms properly

Message ID 20210227132954.7766-10-nick.alcock@oracle.com
State New
Headers show
Series
  • libctf: cleanups, speedups, and bugfixes (one needing review)
Related show

Commit Message

Richard Sandiford via Binutils Feb. 27, 2021, 1:29 p.m.
In the "no symbols" case (commonplace for executables), we were freeing
the ctf_dynsyms using free(), instead of ctf_dynhash_destroy(), leaking
a little memory.

(This is harmless in the common case of ld usage, but libctf might be
used by persistent processes too.)

libctf/ChangeLog
2021-02-25  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-link.c (ctf_link_shuffle_syms): Free ctf_dynsyms properly.
---
 libctf/ChangeLog  | 4 ++++
 libctf/ctf-link.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.30.0.252.gc27e85e57d

Patch

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 01286bcab54..f30f79ec6ee 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,7 @@ 
+2021-02-25  Nick Alcock  <nick.alcock@oracle.com>
+
+	* ctf-link.c (ctf_link_shuffle_syms): Free ctf_dynsyms properly.
+
 2021-02-25  Nick Alcock  <nick.alcock@oracle.com>
 
 	* ctf-dump.c (ctf_dump_format_type): Fix signed/unsigned confusion.
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 05733a0cb7d..882d4297e4f 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -1580,7 +1580,7 @@  ctf_link_shuffle_syms (ctf_dict_t *fp)
   if (!ctf_dynhash_elements (fp->ctf_dynsyms))
     {
       ctf_dprintf ("No symbols: not a final link.\n");
-      free (fp->ctf_dynsyms);
+      ctf_dynhash_destroy (fp->ctf_dynsyms);
       fp->ctf_dynsyms = NULL;
       return 0;
     }