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

Side by Side Diff: webkit/media/crypto/ppapi/cdm_wrapper.cc

Issue 10909068: Fix resource leaks in CDM implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix leaked ref in CdmWrapper::DeliverBlock 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstring> // For memcpy. 5 #include <cstring> // For memcpy.
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/compiler_specific.h" // For OVERRIDE. 8 #include "base/compiler_specific.h" // For OVERRIDE.
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_stdint.h" 10 #include "ppapi/c/pp_stdint.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; 226 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp;
227 227
228 cdm::OutputBuffer output_buffer; 228 cdm::OutputBuffer output_buffer;
229 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer); 229 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer);
230 230
231 CallOnMain(callback_factory_.NewCallback( 231 CallOnMain(callback_factory_.NewCallback(
232 &CdmWrapper::DeliverBlock, 232 &CdmWrapper::DeliverBlock,
233 status, 233 status,
234 output_buffer, 234 output_buffer,
235 encrypted_block_info.tracking_info)); 235 encrypted_block_info.tracking_info));
236
237 return true; 236 return true;
238 } 237 }
239 238
240 bool CdmWrapper::DecryptAndDecode( 239 bool CdmWrapper::DecryptAndDecode(
241 pp::Buffer_Dev encrypted_buffer, 240 pp::Buffer_Dev encrypted_buffer,
242 const PP_EncryptedBlockInfo& encrypted_block_info) { 241 const PP_EncryptedBlockInfo& encrypted_block_info) {
243 return false; 242 return false;
244 } 243 }
245 244
246 PP_Resource CdmWrapper::MakeBufferResource(const uint8_t* data, 245 PP_Resource CdmWrapper::MakeBufferResource(const uint8_t* data,
247 uint32_t data_size) { 246 uint32_t data_size) {
248 if (!data || !data_size) 247 if (!data || !data_size)
249 return 0; 248 return 0;
250 249
251 pp::Buffer_Dev buffer(this, data_size); 250 pp::Buffer_Dev buffer(this, data_size);
252 if (!buffer.data()) 251 if (!buffer.data())
253 return 0; 252 return 0;
254 253
255 memcpy(buffer.data(), data, data_size); 254 memcpy(buffer.data(), data, data_size);
256 255
257 return buffer.detach(); 256 return buffer.detach();
dmichael (off chromium) 2012/09/05 19:46:19 Why not just return pp::Resource?
Tom Finegan 2012/09/05 20:15:26 Done.
258 } 257 }
259 258
260 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) { 259 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) {
261 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id); 260 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id);
262 } 261 }
263 262
264 void CdmWrapper::KeyMessage(int32_t result, 263 void CdmWrapper::KeyMessage(int32_t result,
265 cdm::KeyMessage& key_message) { 264 cdm::KeyMessage& key_message) {
266 pp::Buffer_Dev message_buffer(MakeBufferResource(key_message.message, 265 pp::Buffer_Dev message_buffer(MakeBufferResource(key_message.message,
dmichael (off chromium) 2012/09/05 19:46:19 This one leaks a reference too as-is (but making M
Tom Finegan 2012/09/05 20:15:26 Done.
267 key_message.message_size)); 266 key_message.message_size));
268 pp::ContentDecryptor_Private::KeyMessage( 267 pp::ContentDecryptor_Private::KeyMessage(
269 key_system_, 268 key_system_,
270 std::string(key_message.session_id, key_message.session_id_size), 269 std::string(key_message.session_id, key_message.session_id_size),
271 message_buffer, 270 message_buffer,
272 std::string(key_message.default_url, key_message.default_url_size)); 271 std::string(key_message.default_url, key_message.default_url_size));
273 272
274 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated 273 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated
275 // in another shared object. 274 // in another shared object.
276 delete [] key_message.session_id; 275 delete [] key_message.session_id;
(...skipping 10 matching lines...) Expand all
287 pp::ContentDecryptor_Private::KeyError(key_system_, 286 pp::ContentDecryptor_Private::KeyError(key_system_,
288 session_id, 287 session_id,
289 kUnknownError, 288 kUnknownError,
290 0); 289 0);
291 } 290 }
292 291
293 void CdmWrapper::DeliverBlock(int32_t result, 292 void CdmWrapper::DeliverBlock(int32_t result,
294 const cdm::Status& status, 293 const cdm::Status& status,
295 cdm::OutputBuffer& output_buffer, 294 cdm::OutputBuffer& output_buffer,
296 const PP_DecryptTrackingInfo& tracking_info) { 295 const PP_DecryptTrackingInfo& tracking_info) {
297 pp::Buffer_Dev decrypted_buffer(MakeBufferResource(output_buffer.data, 296 pp::Buffer_Dev decrypted_buffer(pp::PassRef(),
297 MakeBufferResource(output_buffer.data,
298 output_buffer.data_size)); 298 output_buffer.data_size));
299 299
300 PP_DecryptedBlockInfo decrypted_block_info; 300 PP_DecryptedBlockInfo decrypted_block_info;
301 decrypted_block_info.tracking_info.request_id = tracking_info.request_id; 301 decrypted_block_info.tracking_info.request_id = tracking_info.request_id;
302 decrypted_block_info.tracking_info.timestamp = output_buffer.timestamp; 302 decrypted_block_info.tracking_info.timestamp = output_buffer.timestamp;
303 303
304 switch (status) { 304 switch (status) {
305 case cdm::kSuccess: 305 case cdm::kSuccess:
306 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS; 306 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS;
307 break; 307 break;
(...skipping 28 matching lines...) Expand all
336 } // namespace webkit_media 336 } // namespace webkit_media
337 337
338 namespace pp { 338 namespace pp {
339 339
340 // Factory function for your specialization of the Module object. 340 // Factory function for your specialization of the Module object.
341 Module* CreateModule() { 341 Module* CreateModule() {
342 return new webkit_media::MyModule(); 342 return new webkit_media::MyModule();
343 } 343 }
344 344
345 } // namespace pp 345 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_content_decryptor_private_proxy.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698