binutils Newspaper
JUNE 15, 2026
x86/disasm Proposed

x86/disasm: Avoid potentially leaking annotation buffers

Fixes a potential memory leak in the x86 disassembler by ensuring annotation buffers are always freed.

This patch addresses a potential memory leak in the x86 disassembler. The asprintf function can return 0 while still allocating memory, leading to a leak if the free function is only called when asprintf succeeds. The patch moves the free call outside the if statement to ensure the buffer is always freed.

In Details

This patch fixes a memory leak in opcodes/i386-dis.c within the oappend_immediate function. The original code had a conditional free(annotation) call, which would not be executed if asprintf failed but still allocated memory. The fix moves the free call to unconditionally release the allocated memory.

For Context

The disassembler converts machine code into assembly language. This patch addresses a potential memory leak in the x86 disassembler, which could occur when annotating immediates (constant values) in the assembly output. The fix ensures that memory allocated for these annotations is always released, preventing memory exhaustion over time.

Filed Under: x86disassemblermemory leakbugfix