[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 摘要。