From f7b7f86f7f616c55d3d5a0df0237a9210083f725 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 1 Mar 2024 16:40:31 -0500 Subject: [PATCH] Fix a panic on Linux when using samply record --iteration-count 2 ls. --- samply/src/linux/perf_group.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/samply/src/linux/perf_group.rs b/samply/src/linux/perf_group.rs index 27bbc4fd..00b657d4 100644 --- a/samply/src/linux/perf_group.rs +++ b/samply/src/linux/perf_group.rs @@ -239,10 +239,8 @@ impl PerfGroup { for ev in self.poll_events.iter() { if ev.is_read_closed() { - self.members - .get_mut(&(ev.token().0 as RawFd)) - .unwrap() - .is_closed = true; + let fd = ev.token().0 as RawFd; + self.members.get_mut(&fd).unwrap().is_closed = true; } } } @@ -283,6 +281,11 @@ impl PerfGroup { } for fd in fds_to_remove.drain(..) { + let result = self.poll.registry().deregister(&mut SourceFd(&fd)); + if let Err(err) = result { + eprintln!("deregister failed: {}", err); + continue; + } self.members.remove(&fd); }