[PATCH 2/3] x86/disasm: avoid potentially leaking annotation buffers

Jan Beulich jbeulich@suse.com
Fri May 15 13:07:58 GMT 2026


Address the FIXME there by moving the free() invocation out of the if().

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -11697,14 +11697,13 @@ oappend_immediate (instr_info *ins, bfd_
 
   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.  */



More information about the Binutils mailing list