Skip to content

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

Closed

Description

@orthur2

Summary

When revisiting the implementation while preparing to add downgrade(), I found Arc strong-reference leaks in map/filter_map of three owned mapped guards. The bug was introduced by using ManuallyDrop together with Arc::clone(), which leaves the original strong reference stranded in ManuallyDrop and never dropped. This bug was caused by my attempt to prevent the original Guard from releasing its lock and to preserve the Arc reference that provides the lock for the MappedGuard. In fact, I should have transferred ownership of the Arc instead of sharing it.

I am very sorry for writing incorrect Unsafe Rust code. I will fix this issue.

Suggested Fix

I will submit a Pull Request that replaces guard.lock.clone() with unsafe { std::ptr::read(&guard.lock) } in all affected map and filter_map methods. The PR will also include the new tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions