lkml.org 
[lkml]   [2016]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2] [BUGFIX]perf probe: Fix to close target file
Date
Fix a bug to close target elf file in get_text_start_address().

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Changes in v2:
- handle an error case in elf_begin() too.
---
tools/perf/util/probe-event.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 8319fbb..97b7f8e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -486,8 +486,10 @@ static int get_text_start_address(const char *exec, unsigned long *address)
return -errno;

elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
- if (elf == NULL)
- return -EINVAL;
+ if (elf == NULL) {
+ ret = -EINVAL;
+ goto out_close;
+ }

if (gelf_getehdr(elf, &ehdr) == NULL)
goto out;
@@ -499,6 +501,9 @@ static int get_text_start_address(const char *exec, unsigned long *address)
ret = 0;
out:
elf_end(elf);
+out_close:
+ close(fd);
+
return ret;
}

\
 
 \ /
  Last update: 2016-04-26 09:21    [W:0.048 / U:1.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site