diff --git a/content/media/plugins/MediaPluginHost.cpp b/content/media/plugins/MediaPluginHost.cpp index 9b85e1f7d52..f211ffb616f 100644 --- a/content/media/plugins/MediaPluginHost.cpp +++ b/content/media/plugins/MediaPluginHost.cpp @@ -273,15 +273,16 @@ bool MediaPluginHost::FindDecoder(const nsACString& aMimeType, const char* const MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const nsACString& aMimeType) { - const char *chars; - size_t len = NS_CStringGetData(aMimeType, &chars, nullptr); + NS_ENSURE_TRUE(aResource, nullptr); - Decoder *decoder = new Decoder(); + nsAutoPtr decoder(new Decoder()); if (!decoder) { return nullptr; } decoder->mResource = aResource; + const char *chars; + size_t len = NS_CStringGetData(aMimeType, &chars, nullptr); for (size_t n = 0; n < mPlugins.Length(); ++n) { Manifest *plugin = mPlugins[n]; const char* const *codecs; @@ -289,7 +290,8 @@ MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const n continue; } if (plugin->CreateDecoder(&sPluginHost, decoder, chars, len)) { - return decoder; + aResource->AddRef(); + return decoder.forget(); } } @@ -299,6 +301,12 @@ MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const n void MediaPluginHost::DestroyDecoder(Decoder *aDecoder) { aDecoder->DestroyDecoder(aDecoder); + MediaResource* resource = GetResource(aDecoder); + if (resource) { + // resource *shouldn't* be null, but check anyway just in case the plugin + // decoder does something stupid. + resource->Release(); + } delete aDecoder; }