From 150a885dfa8a3a0355e625ecf05e74dc4a4b8f2d Mon Sep 17 00:00:00 2001 From: Henry Chang Date: Tue, 6 Jun 2017 17:51:51 +0800 Subject: [PATCH] Bug 1362182 - Early return if mUpdateObserver has been nulled out by CancelUpdate(). r=francois MozReview-Commit-ID: 2fQCtjMJkx --HG-- extra : rebase_source : 33b16d2c1958d8a4dcd4cfa9eb3b602f2c84aa55 --- .../url-classifier/nsUrlClassifierDBService.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp index 5948aea47818..4e931afa99bd 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp @@ -669,6 +669,20 @@ nsUrlClassifierDBServiceWorker::NotifyUpdateObserver(nsresult aUpdateStatus) NS_ERROR_GET_CODE(updateStatus)); } + if (!mUpdateObserver) { + // In the normal shutdown process, CancelUpdate() would NOT be + // called prior to NotifyUpdateObserver(). However, CancelUpdate() + // is a public API which can be called in the test case at any point. + // If the call sequence is FinishUpdate() then CancelUpdate(), the later + // might be executed before NotifyUpdateObserver() which is triggered + // by the update thread. In this case, we will get null mUpdateObserver. + NS_WARNING("CancelUpdate() is called before we asynchronously call " + "NotifyUpdateObserver() in FinishUpdate()."); + + // The DB cleanup will be done in CancelUpdate() so we can just return. + return NS_OK; + } + // Null out mUpdateObserver before notifying so that BeginUpdate() // becomes available prior to callback. nsCOMPtr updateObserver = nullptr;