[binutils-gdb] x86/disasm: avoid potentially leaking annotation buffers

Jan Beulich via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=037292b02f4c48e80d1ab002cc589fe6c76e96ea

commit 037292b02f4c48e80d1ab002cc589fe6c76e96ea
Author: Jan Beulich <[email protected]>
Date:   Fri May 22 08:48:03 2026 +0200

    x86/disasm: avoid potentially leaking annotation buffers
    
    Address the FIXME there by moving the free() invocation out of the if().

Diff:
---
 opcodes/i386-dis.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index fede65a0aa7..ad0593cedd7 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -11697,14 +11697,13 @@ oappend_immediate (instr_info *ins, bfd_vma imm)
 
   char * annotation = NULL;
 
-  /* FIXME: Potential memory leak: strictly speaking asprintf()
-     can return 0 whilst also having allocated some memory.  */
   if (asprintf (& annotation, " [%s]", sym->name) > 0)
     {
       /* Display the symbol associated with address 'imm'.  */
       cappend_with_style (ins, annotation, dis_style_symbol);
-      free (annotation);
     }
+
+  free (annotation);
 }
 
 /* Put DISP in BUF as signed hex number.  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.