Fix add_ref(Shared) refcounting bug.

This commit is contained in:
4lDO2
2024-06-23 00:35:58 +02:00
parent 7d5b2e6c21
commit 9b68d4de80
3 changed files with 8 additions and 2 deletions
+6
View File
@@ -1602,6 +1602,12 @@ impl Grant {
}
// Cannot be shared and CoW simultaneously.
Err(AddRefError::SharedToCow) => {
// The call to cow() later implicitly removes one ref, so add it here
// first, even if Shared.
if src_page_info.add_ref(RefKind::Shared) == Err(AddRefError::RcOverflow) {
return Err(Enomem);
}
// TODO: Copy in place, or use a zeroed page?
let CowResult { new_frame, old_frame } = cow(src_frame, src_page_info, rk).map_err(|_| Enomem)?;
if let Some(old_frame) = old_frame {