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

Message ID 0568e50d-eaa0-4875-8fff-e44ed2e54341@suse.com
State New
Headers
Series x86/disasm: adjustments to insn annotations |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich May 15, 2026, 1:07 p.m. UTC
  Address the FIXME there by moving the free() invocation out of the if().
  

Patch

--- 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.  */