objtool: Fix memory leak in decode_instructions()

When an error occurs before adding an allocated insn to the list, free
it before returning.

Signed-off-by: Kamalesh Babulal <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/336da800bf6070eae11f4e0a3b9ca64c27658114.1508430423.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
Kamalesh Babulal 2017-10-19 11:27:24 -05:00 • committed by Ingo Molnar
commit b703798386

View file

@ -267,12 +267,13 @@ static int decode_instructions(struct objtool_file *file)
&insn->immediate,
&insn->stack_op);
if (ret)
return ret;
goto err;
if (!insn->type || insn->type > INSN_LAST) {
WARN_FUNC("invalid instruction type %d",
insn->sec, insn->offset, insn->type);
return -1;
ret = -1;
goto err;
}
hash_add(file->insn_hash, &insn->hash, insn->offset);
@ -296,6 +297,10 @@ static int decode_instructions(struct objtool_file *file)
}
return 0;
err:
free(insn);
return ret;
}
/*