Bug: NewAppendableFile does not record newly created FileState in file_map_
- Dominant language
- C++
- Stars
- 39.4k
- Forks
- 8.2k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
I found a potential bug in `helpers/memenv/memenv.cc` in the `InMemoryEnv::NewAppendableFile` method.
## Location
[helpers/memenv/memenv.cc, lines 276-287](https://github.com/google/leveldb/blob/main/helpers/memenv/memenv.cc#L276)
## Problem
When a new appendable file is created (i.e., the file does not exist in `file_map_`), a new `FileState` object is instantiated and referenced. However, **the new FileState is never assigned back to the file_map_**, breaking the association between the filename and the FileState object.
## Current Code
```cpp
Status NewAppendableFile(const std::string& fname,
WritableFile** result) override {
MutexLock lock(&mutex_);
FileState** sptr = &file_map_[fname];
FileState* file = *sptr;
if (file == nullptr) {
file = new FileState();
file->Ref();
// BUG: Missing assignment back to file_map_
}
*result = new WritableFileImpl(file);
return Status::OK();
}
Contributor guide
Assessment
This issue has not been assessed yet.