Skip to content

Map::drop leaks stored values #150

Description

@RAprogramm

While running benchmark tests for sodg.rs issue #232, i observed that memory usage kept growing until the process exhausted available RAM. After investigation, the root cause turned out to be in emap.

The ignored regression test drops_values already documents the intended behavior and still fails without the fix, confirming the problem.

Important

The current Drop implementation on Map<V> only deallocates the raw buffer and never walks through occupied nodes to run the destructors of the stored values, so every V that owns resources (files, reference-counted pointers, etc.) is leaked when the map is dropped.

Impact

  • User code that stores RAII types (e.g., Rc, file handles, network sockets) in the map will leak those resources, breaking invariants and potentially causing use-after-free bugs in dependent code.
  • Because the regression test is #[ignore], the leak can reappear unnoticed in future releases.

Reproduction (conceptual)

  1. Create let mut map = Map::with_capacity(1);.
  2. Insert an Rc into key 0.
  3. Drop the map and observe that Rc::strong_count is still 2 instead of 1 (captured in the ignored drops_values test).

Expectation

Dropping the Map must drop every Some(V) stored in its nodes before deallocating the backing buffer, so all contained values run their destructors exactly once.

Proposed direction

  • Update Drop to iterate over occupied nodes, move out each Option<V>, and drop the values before finally calling dealloc.
  • Audit insert_unchecked, remove_unchecked, and retain for similar drop-handling gaps once the main fix is in place.
  • Re-enable the drops_values regression test to prevent regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions