diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2016-04-26 02:47:37 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-26 09:56:08 -0400 |
commit | 062d6c2aec0e087be956494a73221c04eca115fe (patch) | |
tree | 0f53396a11bb4c4aff693ee66ba32475f888b7e1 | |
parent | b04b7023751bf6519eee64467b6477f0e7fb82a1 (diff) |
perf probe: Close target file on error path
Fix a bug to close target elf file in get_text_start_address().
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20160426064737.1443.44093.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/probe-event.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 8319fbb08636..97b7f8e5fe69 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) | |||
486 | return -errno; | 486 | return -errno; |
487 | 487 | ||
488 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); | 488 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
489 | if (elf == NULL) | 489 | if (elf == NULL) { |
490 | return -EINVAL; | 490 | ret = -EINVAL; |
491 | goto out_close; | ||
492 | } | ||
491 | 493 | ||
492 | if (gelf_getehdr(elf, &ehdr) == NULL) | 494 | if (gelf_getehdr(elf, &ehdr) == NULL) |
493 | goto out; | 495 | goto out; |
@@ -499,6 +501,9 @@ static int get_text_start_address(const char *exec, unsigned long *address) | |||
499 | ret = 0; | 501 | ret = 0; |
500 | out: | 502 | out: |
501 | elf_end(elf); | 503 | elf_end(elf); |
504 | out_close: | ||
505 | close(fd); | ||
506 | |||
502 | return ret; | 507 | return ret; |
503 | } | 508 | } |
504 | 509 | ||