Bug 1791892 - part7 : shutdown gfxconfig and device manager, and use mKind to avoid leaking. r=jolin,gerard-majax

We didn't close gfxconfig and the device manager properly before, which
causes a leak.

Also, using `mKind` to store the kind in the beginning helps us not need
to call `UtilityProcessChild::GetSingleton()` again to check the type,
which would also cause leaking and that would be addressed in bug 1792952.

Depends on D158072

Differential Revision: https://phabricator.services.mozilla.com/D158386
This commit is contained in:
alwu 2022-10-10 20:13:31 +00:00
parent 105fb88ef1
commit b30bf6accf
3 changed files with 23 additions and 20 deletions

View file

@ -26,6 +26,7 @@
#include "VorbisDecoder.h"
#include "WAVDecoder.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/RemoteDecodeUtils.h"
#include "mozilla/RemoteDecoderManagerChild.h"
#include "mozilla/RemoteDecoderModule.h"
#include "mozilla/SharedThreadPool.h"
@ -559,8 +560,7 @@ void PDMFactory::CreateRddPDMs() {
}
void PDMFactory::CreateUtilityPDMs() {
const ipc::SandboxingKind aKind =
ipc::UtilityAudioDecoderParent::GetSandboxingKind();
const ipc::SandboxingKind aKind = GetCurrentSandboxingKind();
#ifdef XP_WIN
if (StaticPrefs::media_wmf_enabled() &&
StaticPrefs::media_utility_wmf_enabled() &&

View file

@ -36,12 +36,14 @@
namespace mozilla::ipc {
UtilityAudioDecoderParent::UtilityAudioDecoderParent() {
UtilityAudioDecoderParent::UtilityAudioDecoderParent()
: mKind(GetCurrentSandboxingKind()) {
#ifdef MOZ_WMF_MEDIA_ENGINE
if (GetCurrentSandboxingKind() == SandboxingKind::MF_MEDIA_ENGINE_CDM) {
if (mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM) {
nsDebugImpl::SetMultiprocessMode("MF Media Engine CDM");
profiler_set_process_name(nsCString("MF Media Engine CDM"));
gfx::gfxConfig::Init();
gfx::gfxVars::Initialize();
gfx::DeviceManagerDx::Init();
return;
}
@ -52,6 +54,16 @@ UtilityAudioDecoderParent::UtilityAudioDecoderParent() {
}
}
UtilityAudioDecoderParent::~UtilityAudioDecoderParent() {
#ifdef MOZ_WMF_MEDIA_ENGINE
if (mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM) {
gfx::gfxConfig::Shutdown();
gfx::gfxVars::Shutdown();
gfx::DeviceManagerDx::Shutdown();
}
#endif
}
/* static */
void UtilityAudioDecoderParent::GenericPreloadForSandbox() {
#if defined(MOZ_SANDBOX) && defined(OS_WIN)
@ -80,15 +92,6 @@ void UtilityAudioDecoderParent::WMFPreloadForSandbox() {
#endif // defined(MOZ_SANDBOX) && defined(OS_WIN)
}
/* static */
SandboxingKind UtilityAudioDecoderParent::GetSandboxingKind() {
RefPtr<UtilityProcessChild> me = UtilityProcessChild::GetSingleton();
if (!me) {
MOZ_CRASH("I cant find myself");
}
return me->mSandbox;
}
void UtilityAudioDecoderParent::Start(
Endpoint<PUtilityAudioDecoderParent>&& aEndpoint) {
MOZ_ASSERT(NS_IsMainThread());
@ -104,8 +107,8 @@ void UtilityAudioDecoderParent::Start(
#endif
auto supported = PDMFactory::Supported();
Unused << SendUpdateMediaCodecsSupported(
GetRemoteDecodeInFromKind(GetSandboxingKind()), supported);
Unused << SendUpdateMediaCodecsSupported(GetRemoteDecodeInFromKind(mKind),
supported);
}
mozilla::ipc::IPCResult
@ -123,7 +126,7 @@ mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge(
Endpoint<PVideoBridgeChild>&& aEndpoint,
nsTArray<gfx::GfxVarUpdate>&& aUpdates,
const ContentDeviceData& aContentDeviceData) {
MOZ_ASSERT(GetCurrentSandboxingKind() == SandboxingKind::MF_MEDIA_ENGINE_CDM);
MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM);
if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess(
std::move(aEndpoint))) {
return IPC_FAIL_NO_REASON(this);
@ -154,7 +157,7 @@ mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge(
IPCResult UtilityAudioDecoderParent::RecvUpdateVar(
const GfxVarUpdate& aUpdate) {
MOZ_ASSERT(GetCurrentSandboxingKind() == SandboxingKind::MF_MEDIA_ENGINE_CDM);
MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM);
gfx::gfxVars::ApplyUpdate(aUpdate);
return IPC_OK();
}

View file

@ -43,10 +43,10 @@ class UtilityAudioDecoderParent final : public PUtilityAudioDecoderParent {
IPCResult RecvUpdateVar(const mozilla::gfx::GfxVarUpdate& aUpdate);
#endif
static SandboxingKind GetSandboxingKind();
private:
~UtilityAudioDecoderParent() = default;
~UtilityAudioDecoderParent();
const SandboxingKind mKind;
};
} // namespace mozilla::ipc