Skip to content

Bug: NewAppendableFile does not record newly created FileState in file_map_ #1328

Description

@puzc1993

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions