]> git.karo-electronics.de Git - linux-beck.git/commitdiff
perf probe: Close target file on error path
authorMasami Hiramatsu <mhiramat@kernel.org>
Tue, 26 Apr 2016 06:47:37 +0000 (15:47 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 26 Apr 2016 13:56:08 +0000 (10:56 -0300)
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>
tools/perf/util/probe-event.c

index 8319fbb0863618f9d5bff52f17559dc2ab23e2b7..97b7f8e5fe69e24fd00f39edc70e5ca350b22bd2 100644 (file)
@@ -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;
 }