Skip to content

Commit

Permalink
PPAPI: Fix WebSocket Var ref leak receiving binary
Browse files Browse the repository at this point in the history
BUG=173503


Review URL: https://chromiumcodereview.appspot.com/12096099

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180093 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dmichael@chromium.org committed Feb 1, 2013
1 parent 721b7aa commit 2b49834
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ppapi/proxy/websocket_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ void WebSocketResource::OnPluginMsgReceiveBinaryReply(
return;

// Append received data to queue.
scoped_refptr<Var> message_var(ArrayBufferVar::FromPPVar(
PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
scoped_refptr<Var> message_var(
PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferVar(
message.size(),
&message.front())));
&message.front()));
received_messages_.push(message_var);

if (!TrackedCallback::IsPending(receive_callback_))
Expand Down
13 changes: 9 additions & 4 deletions ppapi/shared_impl/var_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes) {

PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes,
const void* data) {
DCHECK(CalledOnValidThread());
ArrayBufferVar* array_buffer = MakeArrayBufferVar(size_in_bytes, data);
return array_buffer ? array_buffer->GetPPVar() : PP_MakeNull();
}

scoped_refptr<ArrayBufferVar> array_buffer(CreateArrayBuffer(size_in_bytes));
ArrayBufferVar* VarTracker::MakeArrayBufferVar(uint32 size_in_bytes,
const void* data) {
DCHECK(CalledOnValidThread());
ArrayBufferVar* array_buffer(CreateArrayBuffer(size_in_bytes));
if (!array_buffer)
return PP_MakeNull();
return NULL;
memcpy(array_buffer->Map(), data, size_in_bytes);
return array_buffer->GetPPVar();
return array_buffer;
}

std::vector<PP_Var> VarTracker::GetLiveVars() {
Expand Down
6 changes: 6 additions & 0 deletions ppapi/shared_impl/var_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class PPAPI_SHARED_EXPORT VarTracker
// Same as above, but copy the contents of |data| in to the new array buffer.
PP_Var MakeArrayBufferPPVar(uint32 size_in_bytes, const void* data);

// Create an ArrayBuffer and copy the contents of |data| in to it. The
// returned object has 0 reference count in the tracker, and like all
// RefCounted objects, has a 0 initial internal reference count. (You should
// usually immediately put this in a scoped_refptr).
ArrayBufferVar* MakeArrayBufferVar(uint32 size_in_bytes, const void* data);

// Return a vector containing all PP_Vars that are in the tracker. This is
// to help implement PPB_Testing_Dev.GetLiveVars and should generally not be
// used in production code. The PP_Vars are returned in no particular order,
Expand Down
2 changes: 1 addition & 1 deletion ppapi/tests/test_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class TestCaseFactory {
instance_->pp_instance()) != objects) \
error_message = MakeFailureMessage(__FILE__, __LINE__, \
"reference leak check"); \
instance_->LogTest(#name, error_message); \
instance_->LogTest(#name, CheckResourcesAndVars(error_message)); \
}

// Helper macros for checking values in tests, and returning a location
Expand Down
1 change: 1 addition & 0 deletions ppapi/tests/test_websocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ std::string TestWebSocket::TestValidConnect() {
PP_Var extensions = websocket_interface_->GetExtensions(ws);
ASSERT_TRUE(AreEqualWithString(extensions, ""));
core_interface_->ReleaseResource(ws);
ReleaseVar(extensions);

PASS();
}
Expand Down

0 comments on commit 2b49834

Please sign in to comment.