While monitoring a multithread process with pid option, if any of the
threads exit before we open the event fd, we can ignore the missing
thread.

We use perf_evsel__remove_fd() to remove the FD of the missing thread,
but we missed to close these fds. This patch explicitly closes the fd
before remove it.

Fixes: ca8000684ec4 ("perf evsel: Enable ignore_missing_thread for pid option")
Signed-off-by: Cheng Jian <cj.chengj...@huawei.com>
---
 tools/perf/util/evsel.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index eb880efbce16..cbb04a18839c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1489,9 +1489,13 @@ static void perf_evsel__remove_fd(struct evsel *pos,
                                  int nr_cpus, int nr_threads,
                                  int thread_idx)
 {
-       for (int cpu = 0; cpu < nr_cpus; cpu++)
-               for (int thread = thread_idx; thread < nr_threads - 1; thread++)
+       for (int cpu = 0; cpu < nr_cpus; cpu++) {
+               for (int thread = thread_idx;
+                    thread < nr_threads - 1; thread++) {
+                       close(FD(pos, cpu, thread));
                        FD(pos, cpu, thread) = FD(pos, cpu, thread + 1);
+               }
+       }
 }
 
 static int update_fds(struct evsel *evsel,
-- 
2.17.1

Reply via email to