Bug 1543331 - Add a null check before calling mHostResolver->FlushCache() r=dragana

frame #5 of report https://crash-stats.mozilla.org/report/index/4dca6cb1-8d45-4bf5-8836-216810200217

This crash was rather obvious in retrospect, but I missed it because I was
looking at the wrong thing. We're not actually crashing in FlushCache,
instead mHostResolver is null in nsDNSService::Observe

What made it obvious is frame #5 of report https://crash-stats.mozilla.org/report/index/4dca6cb1-8d45-4bf5-8836-216810200217
Included here because crash reports expire:

```
1   libxul.so   nsHostResolver::FlushCache(bool)  netwerk/dns/nsHostResolver.cpp:740
2   libxul.so   nsDNSService::Observe(nsISupports*, char const*, char16_t const*)   netwerk/dns/nsDNSService2.cpp:1132
3   libxul.so   nsObserverList::NotifyObservers(nsISupports*, char const*, char16_t const*)   xpcom/ds/nsObserverList.cpp:66
4   libxul.so   nsObserverService::NotifyObservers(nsISupports*, char const*, char16_t const*)  xpcom/ds/nsObserverService.cpp:295
5   libxul.so   DecreasePrivateDocShellCount()  docshell/base/nsDocShell.cpp:306
6   libxul.so   nsDocShell::Destroy()   docshell/base/nsDocShell.cpp:5076
```

See the code points to this line:
ef373efc99/docshell/base/nsDocShell.cpp (l306)

As we can see, it emits the "last-pb-context-exited" notification,
and nsDNSService tries to call FlushCache.
However, it appears this notification may be called after we get the shutdown
notification and we null out the pointer. It's unclear why this crash was not
noticed before bug 1450893 landed.

Depends on D63107

Differential Revision: https://phabricator.services.mozilla.com/D63108

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2020-02-17 22:20:12 +00:00
Родитель 541f162e0b
Коммит 482d3cd412
1 изменённых файлов: 2 добавлений и 1 удалений

Просмотреть файл

@ -1223,7 +1223,7 @@ nsDNSService::Observe(nsISupports* subject, const char* topic,
Shutdown();
}
if (flushCache) {
if (flushCache && mResolver) {
mResolver->FlushCache(false);
return NS_OK;
}
@ -1293,6 +1293,7 @@ nsDNSService::GetDNSCacheEntries(
NS_IMETHODIMP
nsDNSService::ClearCache(bool aTrrToo) {
NS_ENSURE_TRUE(mResolver, NS_ERROR_NOT_INITIALIZED);
mResolver->FlushCache(aTrrToo);
return NS_OK;
}