Skip to content

rocksdb: list iterator invalidation #55

@qqiangwu

Description

@qqiangwu
void WriteBufferManager::RemoveDBFromQueue(StallInterface* wbm_stall) {
  assert(wbm_stall != nullptr);

  // Deallocate the removed nodes outside of the lock.
  std::list<StallInterface*> cleanup;

  if (enabled() && allow_stall_.load(std::memory_order_relaxed)) {
    std::unique_lock<std::mutex> lock(mu_);
    for (auto it = queue_.begin(); it != queue_.end();) {
      auto next = std::next(it);
      if (*it == wbm_stall) {
        cleanup.splice(cleanup.end(), queue_, std::move(it));
      }
      it = next;
    }
  }
  wbm_stall->Signal();
}

gives:

/Users/wuqq/dev/rocksdb-main/memtable/write_buffer_manager.cc:174:36: warning: passing a possibly dangling pointer as argument
  174 |     for (auto it = queue_.begin(); it != queue_.end();) {
      |                                    ^~
/Users/wuqq/dev/rocksdb-main/memtable/write_buffer_manager.cc:177:39: note: modified here
  177 |         cleanup.splice(cleanup.end(), queue_, std::move(it));
      |                                       ^~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions