Bug 862182 - Hold references to MediaResource in nsRefPtrs (content/media/plugins). r=doublec
authorChris Pearce <cpearce@mozilla.com>
Wed, 01 May 2013 11:23:46 +1200
changeset 141374 64d208186331e6bf17ea8b712354ca02f01b6013
parent 141373 50df37d5f7684700121eeda21950964fd18996e9
child 141375 5378db8362f54a94fb8bc8360990e04f70996bb9
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs862182
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 862182 - Hold references to MediaResource in nsRefPtrs (content/media/plugins). r=doublec
content/media/plugins/MediaPluginHost.cpp
--- a/content/media/plugins/MediaPluginHost.cpp
+++ b/content/media/plugins/MediaPluginHost.cpp
@@ -268,42 +268,50 @@ bool MediaPluginHost::FindDecoder(const 
       return true;
     }
   }
   return false;
 }
 
 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> 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;
     if (!plugin->CanDecode(chars, len, &codecs)) {
       continue;
     }
     if (plugin->CreateDecoder(&sPluginHost, decoder, chars, len)) {
-      return decoder;
+      aResource->AddRef();
+      return decoder.forget();
     }
   }
 
   return nullptr;
 }
 
 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;
 }
 
 MediaPluginHost *sMediaPluginHost = nullptr;
 MediaPluginHost *GetMediaPluginHost()
 {
   if (!sMediaPluginHost) {
     sMediaPluginHost = new MediaPluginHost();