mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] objtool: Fix memory leak in decode_instructions()
@ 2017-10-19 16:27 Josh Poimboeuf
  2017-10-20  7:45 ` [tip:core/urgent] " tip-bot for Kamalesh Babulal
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Poimboeuf @ 2017-10-19 16:27 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel, Kamalesh Babulal

From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>

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

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/objtool/check.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 83f370fa00c2..9b341584eb1b 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -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;
 }
 
 /*
-- 
2.13.6

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip:core/urgent] objtool: Fix memory leak in decode_instructions()
  2017-10-19 16:27 [PATCH] objtool: Fix memory leak in decode_instructions() Josh Poimboeuf
@ 2017-10-20  7:45 ` tip-bot for Kamalesh Babulal
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Kamalesh Babulal @ 2017-10-20  7:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jpoimboe, hpa, tglx, torvalds, mingo, peterz, kamalesh, linux-kernel

Commit-ID:  b703798386fb7288d5a995bd2284a984a5e24f3c
Gitweb:     https://git.kernel.org/tip/b703798386fb7288d5a995bd2284a984a5e24f3c
Author:     Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
AuthorDate: Thu, 19 Oct 2017 11:27:24 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 20 Oct 2017 09:43:21 +0200

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 <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/336da800bf6070eae11f4e0a3b9ca64c27658114.1508430423.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/objtool/check.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index a0c518e..c0e26ad 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -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;
 }
 
 /*

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-20  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 16:27 [PATCH] objtool: Fix memory leak in decode_instructions() Josh Poimboeuf
2017-10-20  7:45 ` [tip:core/urgent] " tip-bot for Kamalesh Babulal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®