Skip to content

Commit

Permalink
Fix Potential Double Free
Browse files Browse the repository at this point in the history
Implementing mem::ManuallyDrop instead of mem::forget
  • Loading branch information
kuzeyardabulut authored Aug 2, 2023
1 parent f2c5458 commit 68829b6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions notify/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,13 @@ fn start_read(rd: &ReadData, event_handler: Arc<Mutex<dyn EventHandler>>, handle

if ret == 0 {
// error reading. retransmute request memory to allow drop.
// allow overlapped to drop by dropping ManuallyDrop
// allow overlapped to drop by omitting forget()
let request: Box<ReadDirectoryRequest> = mem::transmute(request_p);
std::mem::ManuallyDrop::drop(&mut overlapped);

ReleaseSemaphore(request.data.complete_sem, 1, ptr::null_mut());
} else {
// read ok. forget overlapped to let the completion routine handle memory
std::mem::ManuallyDrop::drop(&mut overlapped);
}
}
}
Expand Down

0 comments on commit 68829b6

Please sign in to comment.