#1328·leveldb

Bug: NewAppendableFile does not record newly created FileState in file_map_

Author: puzc1993Created May 23, 2026Updated May 23, 2026

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

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();
}