Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in leveldb_filterpolicy_create_bloom Function #1182

Open
YancyLii opened this issue Apr 21, 2024 · 0 comments
Open

Memory Leak in leveldb_filterpolicy_create_bloom Function #1182

YancyLii opened this issue Apr 21, 2024 · 0 comments

Comments

@YancyLii
Copy link

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

  • The function creates a Wrapper object, which owns a FilterPolicy instance allocated by NewBloomFilterPolicy.
  • The Wrapper destructor is supposed to manage the lifecycle of the FilterPolicy instance. However, if an exception or an early return occurs before the Wrapper object is assigned to a managing pointer or if the leveldb_filterpolicy_destroy function does not perform the deletion correctly, the allocated memory is not freed, resulting in a memory leak.

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

  • Operating System: [Your Operating System]
  • Architecture: [e.g., x86_64]
  • LevelDB Version: [Specify the version or commit hash]

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

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

No branches or pull requests

1 participant