[Storage] desktop ListenerInternal never initializes rest_operation_

オープン 初心者向け
#1,966 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/firebase-cpp-sdk のほかの issue

firebase/firebase-cpp-sdk の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。