From a189c5b9372b207ec9befdfbfd7a6846729fce78 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 23 Jan 2019 14:47:52 +0100 Subject: [PATCH] Fix CefResourceHandler leak in DownloadTest.Pending* --- tests/ceftests/download_unittest.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/ceftests/download_unittest.cc b/tests/ceftests/download_unittest.cc index 47795919b..3274da4d1 100644 --- a/tests/ceftests/download_unittest.cc +++ b/tests/ceftests/download_unittest.cc @@ -323,6 +323,9 @@ class DownloadTestHandler : public TestHandler { CefRefPtr callback) override { EXPECT_TRUE(CefCurrentlyOn(TID_UI)); + if (destroyed_) + return; + got_on_download_updated_.yes(); EXPECT_TRUE(browser->IsSame(GetBrowser())); @@ -366,8 +369,10 @@ class DownloadTestHandler : public TestHandler { EXPECT_LE(0LL, download_item->GetReceivedBytes()); } - if (test_mode_ == PENDING) + if (test_mode_ == PENDING) { + download_item_callback_ = callback; ContinuePendingIfReady(); + } } void VerifyResultsOnFileThread() { @@ -397,6 +402,14 @@ class DownloadTestHandler : public TestHandler { return; } + destroyed_ = true; + + if (download_item_callback_) { + // Cancel the pending download to avoid leaking request objects. + download_item_callback_->Cancel(); + download_item_callback_ = nullptr; + } + if (request_context_) { request_context_->RegisterSchemeHandlerFactory("http", kTestDomain, nullptr); @@ -448,13 +461,17 @@ class DownloadTestHandler : public TestHandler { CefRefPtr request_context_; - // Used with NAVIGATED test mode. + // Used with NAVIGATED and PENDING test modes. CefRefPtr delay_callback_; + // Used with PENDING test mode. + CefRefPtr download_item_callback_; + CefScopedTempDir temp_dir_; std::string test_path_; uint32 download_id_; bool verified_results_; + bool destroyed_ = false; TrackCallback got_download_request_; TrackCallback got_on_before_download_;