* [PATCH] tools: objtool: fix memory leak in elf_create_rela_section()
@ 2017-09-13 18:52 Martin Kepplinger
0 siblings, 0 replies; 3+ messages in thread
From: Martin Kepplinger @ 2017-09-13 18:52 UTC (permalink / raw)
To: jpoimboe; +Cc: linux-kernel, Martin Kepplinger
Let's free the allocated char array relaname before returning
in order to avoid leaking memory.
Signed-off-by: Martin Kepplinger <martink@posteo.de>
---
tools/objtool/elf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6e9f980a7d26..6aacbc31316d 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -508,8 +508,12 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base)
strcat(relaname, base->name);
sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0);
- if (!sec)
+ if (!sec) {
+ free(relaname);
return NULL;
+ }
+
+ free(relaname);
base->rela = sec;
sec->base = base;
--
2.11.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] tools: objtool: fix memory leak in elf_create_rela_section()
@ 2017-09-13 22:41 Josh Poimboeuf
2017-09-14 5:31 ` Ingo Molnar
0 siblings, 1 reply; 3+ messages in thread
From: Josh Poimboeuf @ 2017-09-13 22:41 UTC (permalink / raw)
To: Ingo Molnar; +Cc: linux-kernel, Martin Kepplinger
From: Martin Kepplinger <martink@posteo.de>
Let's free the allocated char array relaname before returning
in order to avoid leaking memory.
Signed-off-by: Martin Kepplinger <martink@posteo.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
tools/objtool/elf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6e9f980a7d26..6aacbc31316d 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -508,8 +508,12 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base)
strcat(relaname, base->name);
sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0);
- if (!sec)
+ if (!sec) {
+ free(relaname);
return NULL;
+ }
+
+ free(relaname);
base->rela = sec;
sec->base = base;
--
2.13.5
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tools: objtool: fix memory leak in elf_create_rela_section()
2017-09-13 22:41 Josh Poimboeuf
@ 2017-09-14 5:31 ` Ingo Molnar
0 siblings, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2017-09-14 5:31 UTC (permalink / raw)
To: Josh Poimboeuf; +Cc: linux-kernel, Martin Kepplinger
* Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> From: Martin Kepplinger <martink@posteo.de>
>
> Let's free the allocated char array relaname before returning
> in order to avoid leaking memory.
>
> Signed-off-by: Martin Kepplinger <martink@posteo.de>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> tools/objtool/elf.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index 6e9f980a7d26..6aacbc31316d 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -508,8 +508,12 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base)
> strcat(relaname, base->name);
>
> sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0);
> - if (!sec)
> + if (!sec) {
> + free(relaname);
> return NULL;
> + }
> +
> + free(relaname);
Erm, I'm quite sure if you read this code a second time you'll see how this
pattern could be improved! ;-)
Thanks,
Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-14 5:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-13 18:52 [PATCH] tools: objtool: fix memory leak in elf_create_rela_section() Martin Kepplinger
2017-09-13 22:41 Josh Poimboeuf
2017-09-14 5:31 ` Ingo Molnar
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®