perf tools: Fix error path to do closedir() when synthesizing threads
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Apr 2015 14:57:03 +0000 (11:57 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 10 Apr 2015 13:13:58 +0000 (10:13 -0300)
When traversing /proc to synthesize the PERF_RECORD_FORK et al events we
were bailing out on errors without calling closedir(), fix it.

Reported-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-vxtp593rfztgbi8noy0m967p@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/event.c

index 9d09851312522e78d3ffebc733933fa222083100..ff866c4d2e2f09ea4abc1650d7c413776b3bb93f 100644 (file)
@@ -387,6 +387,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
        DIR *tasks;
        struct dirent dirent, *next;
        pid_t tgid, ppid;
+       int rc = 0;
 
        /* special case: only send one comm event using passed in pid */
        if (!full) {
@@ -414,38 +415,38 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 
        while (!readdir_r(tasks, &dirent, &next) && next) {
                char *end;
-               int rc = 0;
                pid_t _pid;
 
                _pid = strtol(dirent.d_name, &end, 10);
                if (*end)
                        continue;
 
+               rc = -1;
                if (perf_event__prepare_comm(comm_event, _pid, machine,
                                             &tgid, &ppid) != 0)
-                       return -1;
+                       break;
 
                if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
                                                ppid, process, machine) < 0)
-                       return -1;
+                       break;
                /*
                 * Send the prepared comm event
                 */
                if (process(tool, comm_event, &synth_sample, machine) != 0)
-                       return -1;
+                       break;
 
+               rc = 0;
                if (_pid == pid) {
                        /* process the parent's maps too */
                        rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
                                                process, machine, mmap_data);
+                       if (rc)
+                               break;
                }
-
-               if (rc)
-                       return rc;
        }
 
        closedir(tasks);
-       return 0;
+       return rc;
 }
 
 int perf_event__synthesize_thread_map(struct perf_tool *tool,