Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: ppapi/proxy/ppp_content_decryptor_private_proxy.cc

Issue 10909068: Fix resource leaks in CDM implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates per last set of comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/cpp/private/content_decryptor_private.cc ('k') | webkit/media/crypto/ppapi/cdm_wrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/ppp_content_decryptor_private_proxy.cc
diff --git a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc
index fe6a928a64f753b7242e40971a832670f0c2bb56..5314939694af08b5af635ac6fe8b2f6b905cf2e1 100644
--- a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc
+++ b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc
@@ -75,6 +75,22 @@ PP_Var ExtractReceivedVarAndAddRef(Dispatcher* dispatcher,
return var;
}
+// Increments the reference count on |resource| to ensure that it remains valid
+// until the plugin receives the resource within the asynchronous message sent
+// from the proxy. The plugin side takes ownership of that reference. Returns
+// PP_TRUE when the reference is successfully added, PP_FALSE otherwise.
+PP_Bool AddRefResourceForPlugin(HostDispatcher* dispatcher,
+ PP_Resource resource) {
+ const PPB_Core* core = static_cast<const PPB_Core*>(
+ dispatcher->local_get_interface()(PPB_CORE_INTERFACE));
+ if (!core) {
+ NOTREACHED();
+ return PP_FALSE;
+ }
+ core->AddRefResource(resource);
+ return PP_TRUE;
+}
+
PP_Bool GenerateKeyRequest(PP_Instance instance,
PP_Var key_system,
PP_Var init_data) {
@@ -133,18 +149,12 @@ PP_Bool Decrypt(PP_Instance instance,
NOTREACHED();
return PP_FALSE;
}
- const PPB_Core* core = static_cast<const PPB_Core*>(
- dispatcher->local_get_interface()(PPB_CORE_INTERFACE));
- if (!core) {
+
+ if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) {
NOTREACHED();
return PP_FALSE;
}
- // We need to take a ref on the resource now. The browser may drop
- // references once we return from here, but we're sending an asynchronous
- // message. The plugin side takes ownership of that reference.
- core->AddRefResource(encrypted_block);
-
HostResource host_resource;
host_resource.SetHostResource(instance, encrypted_block);
@@ -184,6 +194,11 @@ PP_Bool DecryptAndDecode(PP_Instance instance,
return PP_FALSE;
}
+ if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) {
+ NOTREACHED();
+ return PP_FALSE;
+ }
+
HostResource host_resource;
host_resource.SetHostResource(instance, encrypted_block);
« no previous file with comments | « ppapi/cpp/private/content_decryptor_private.cc ('k') | webkit/media/crypto/ppapi/cdm_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698