google / leveldb

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.
BSD 3-Clause "New" or "Revised" License
35.71k stars 7.72k forks source link

Memory Leak in leveldb_filterpolicy_create_bloom Function #1182

Open YancyLii opened 2 months ago

YancyLii commented 2 months ago

Title

Memory Leak in leveldb_filterpolicy_create_bloom Function

Body

Description There appears to be a potential memory leak in the implementation of leveldb_filterpolicy_create_bloom in db/c.cc. The leak occurs when an instance of Wrapper, which internally manages a FilterPolicy object, is not properly destroyed under certain conditions, leading to memory not being freed.

Leak Details

Steps to Reproduce

  1. Call leveldb_filterpolicy_create_bloom with a specific bits_per_key.
  2. Simulate an exception or an early return before the function completes.
  3. Observe that the memory allocated for the FilterPolicy instance is not freed.

Expected Behavior All allocated memory should be properly managed and freed when no longer needed.

Possible Fix Ensure that all error paths and exceptional conditions are handled appropriately, and that the leveldb_filterpolicy_destroy function correctly deletes the Wrapper object.

System Information

Additional Information

Please consider reviewing the exception safety of the function to ensure that resources are always released correctly, regardless of the execution path.

Labels

bug, memory-leak