Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in ReceiveSignals #96

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,31 @@ impl fmt::Debug for ReceiveSignals {

impl Drop for ReceiveSignals {
fn drop(&mut self) {
if let OpState::Running(op_index) = self.state {
// Only drop the signal `info` field once we know the operation has
// finished, otherwise the kernel might write into memory we have
// deallocated.
// SAFETY: we're in the `Drop` implementation, so `self.info` can't
// be used anymore making it safe to take ownership.
let resource = unsafe { ManuallyDrop::take(&mut self.info) };
let result = self
.signals
.fd
.sq
.cancel_op(op_index, resource, |submission| unsafe {
submission.cancel_op(op_index);
// We'll get a canceled completion event if we succeeded, which
// is sufficient to cleanup the operation.
submission.no_completion_event();
});
if let Err(err) = result {
log::error!(
let signal_info = unsafe { ManuallyDrop::take(&mut self.info) };
match self.state {
OpState::Running(op_index) => {
// Only drop the signal `info` field once we know the operation has
// finished, otherwise the kernel might write into memory we have
// deallocated.
// SAFETY: we're in the `Drop` implementation, so `self.info` can't
// be used anymore making it safe to take ownership.
let result =
self.signals
.fd
.sq
.cancel_op(op_index, signal_info, |submission| unsafe {
submission.cancel_op(op_index);
// We'll get a canceled completion event if we succeeded, which
// is sufficient to cleanup the operation.
submission.no_completion_event();
});
if let Err(err) = result {
log::error!(
"dropped a10::ReceiveSignals before canceling it, attempt to cancel failed: {err}"
);
}
}
OpState::NotStarted(()) | OpState::Done => drop(signal_info),
}
}
}