mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] objtool: Fix memory leak in decode_instructions()
@ 2017-10-12  9:02 Kamalesh Babulal
  2017-10-12 16:10 ` Josh Poimboeuf
  0 siblings, 1 reply; 13+ messages in thread
From: Kamalesh Babulal @ 2017-10-12  9:02 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Kamalesh Babulal, linux-kernel

free the allocated insn before returning, when an error occurs
before adding insn to file->insn_list.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.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 a0c518ecf085..c0e26ad1fa7e 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.11.0

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH] objtool: Fix memory leak in decode_instructions()
@ 2017-10-19 16:27 Josh Poimboeuf
  0 siblings, 0 replies; 13+ 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] 13+ messages in thread

end of thread, other threads:[~2017-10-22  9:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-12  9:02 [PATCH] objtool: Fix memory leak in decode_instructions() Kamalesh Babulal
2017-10-12 16:10 ` Josh Poimboeuf
2017-10-13  4:44   ` Kamalesh Babulal
2017-10-13  5:06     ` Josh Poimboeuf
2017-10-13  5:50       ` Kamalesh Babulal
2017-10-19 14:31         ` Josh Poimboeuf
2017-10-19 14:32           ` Josh Poimboeuf
2017-10-22  9:25             ` Kamalesh Babulal
2017-10-19 14:12   ` Josh Poimboeuf
2017-10-19 15:21     ` Ingo Molnar
2017-10-19 15:34       ` Josh Poimboeuf
2017-10-20  7:24         ` Ingo Molnar
2017-10-19 16:27 Josh Poimboeuf

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

Powered by JetHome