[Storage] desktop ListenerInternal never initializes rest_operation_

未關閉 適合新手
#1,966 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
cpp
領域
backend

研究方向

在 storage/src/desktop/listener_desktop.cc 中,建構函式會初始化 listener_、bytes_transferred_ 和 total_byte_count_;issue 指出 rest_operation_ 沒有標頭檔初始化器。閱讀 ListenerInternal 的宣告和建構函式,接著檢查在建立 RestOperation 之前 PutFile 失敗時所使用 listener 的解構函式行為。完成的標準是該情況不再存取未初始化的指標。

由索引模型根據 Issue 內容生成。

描述

storage/src/desktop/listener_desktop.cc:

ListenerInternal::ListenerInternal(Listener *listener)
    : listener_(listener), bytes_transferred_(-1), total_byte_count_(-1) {}

ListenerInternal::~ListenerInternal() {
  MutexLock lock(mutex_);
  if (rest_operation_) {
    rest_operation_->cleanup().UnregisterObject(this);
    rest_operation_->set_listener(nullptr);
  }
}

rest_operation_ has no initializer in the header either. It only gets set in set_rest_operation(), which runs when a RestOperation is created.

So a Listener passed to a call that never creates one gets destroyed with garbage in it. PutFile() on a path that can't be opened does this. PutFileInternal completes with "Could not read file." and returns before RestCall.

class L : public firebase::storage::Listener {
  void OnPaused(firebase::storage::Controller*) override {}
  void OnProgress(firebase::storage::Controller*) override {}
};

auto* l = new L();
auto f = ref.PutFile("/no/such/file", l);
// wait for f, it fails with kErrorUnknown
delete l;
  • Windows x64, MSVC release: access violation in the destructor
  • Linux and macOS: passes, the allocation happened to be zeroed

13.12.0, and main is the same.

Fix is rest_operation_(nullptr) in the constructor.

主要語言
C++
星號
326
分支
137
平均合併
3 天 8 小時
30 天內合併 PR
17

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

firebase/firebase-cpp-sdk 的其他 Issue

查看 firebase/firebase-cpp-sdk 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。