Skip to content

fix: Eliminate Arc memory leaks in Owned* guards map/filter_map - #64

Merged
tisonkun merged 1 commit into
apache:mainfrom
orthur2:fix/three_owned_guard_memory_leak
Aug 21, 2025
Merged

tisonkun merged 1 commit into
apache:mainfrom
orthur2:fix/three_owned_guard_memory_leak

Conversation

@orthur2

@orthur2 orthur2 commented Aug 8, 2025 •

Copy link
Copy Markdown
Contributor

Fix Arc memory leaks in:

  • OwnedRwLockWriteGuard::{map, filter_map}
  • OwnedMappedRwLockWriteGuard::{map, filter_map}
  • OwnedMappedRwLockReadGuard::{map, filter_map}

Why?

Using ManuallyDrop together with Arc::clone() leaves the original strong ref stranded in ManuallyDrop, effectively leaking one strong ref per call.

Solution:

Replace ManuallyDrop + clone with ManuallyDrop + std::ptr::read(&orig.lock) to move the Arc out and transfer ownership to the new guard.

Files changed

  • mea/src/rwlock/owned_write_guard.rs
  • mea/src/rwlock/owned_mapped_write_guard.rs
  • mea/src/rwlock/owned_mapped_read_guard.rs
  • mea/src/rwlock/test.rs

Closes: #63

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! LGTM.

@tisonkun
tisonkun merged commit 1b62f3c into apache:main Aug 21, 2025
@orthur2
orthur2 deleted the fix/three_owned_guard_memory_leak branch August 30, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Memory leak in map/filter_map for Owned* guards

2 participants