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

Unified Diff: ppapi/cpp/var.cc

Issue 10905128: Pepper WebSocket API: Fix memory leak issue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no leak! 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/var.h ('k') | ppapi/cpp/var_array_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/var.cc
diff --git a/ppapi/cpp/var.cc b/ppapi/cpp/var.cc
index 3e76593bd2763ff5fec11c110bef977ea0a8dc1a..7fc67f5b273e754e4b296a030e781c3bb56345e8 100644
--- a/ppapi/cpp/var.cc
+++ b/ppapi/cpp/var.cc
@@ -59,65 +59,63 @@ PP_Var VarFromUtf8Helper(const char* utf8_str, uint32_t len) {
Var::Var() {
memset(&var_, 0, sizeof(var_));
var_.type = PP_VARTYPE_UNDEFINED;
- needs_release_ = false;
+ is_managed_ = true;
}
Var::Var(Null) {
memset(&var_, 0, sizeof(var_));
var_.type = PP_VARTYPE_NULL;
- needs_release_ = false;
+ is_managed_ = true;
}
Var::Var(bool b) {
var_.type = PP_VARTYPE_BOOL;
var_.padding = 0;
var_.value.as_bool = PP_FromBool(b);
- needs_release_ = false;
+ is_managed_ = true;
}
Var::Var(int32_t i) {
var_.type = PP_VARTYPE_INT32;
var_.padding = 0;
var_.value.as_int = i;
- needs_release_ = false;
+ is_managed_ = true;
}
Var::Var(double d) {
var_.type = PP_VARTYPE_DOUBLE;
var_.padding = 0;
var_.value.as_double = d;
- needs_release_ = false;
+ is_managed_ = true;
}
Var::Var(const char* utf8_str) {
uint32_t len = utf8_str ? static_cast<uint32_t>(strlen(utf8_str)) : 0;
var_ = VarFromUtf8Helper(utf8_str, len);
- needs_release_ = (var_.type == PP_VARTYPE_STRING);
+ is_managed_ = true;
}
Var::Var(const std::string& utf8_str) {
var_ = VarFromUtf8Helper(utf8_str.c_str(),
- static_cast<uint32_t>(utf8_str.size()));
- needs_release_ = (var_.type == PP_VARTYPE_STRING);
+ static_cast<uint32_t>(utf8_str.size()));
+ is_managed_ = true;
}
Var::Var(const Var& other) {
var_ = other.var_;
+ is_managed_ = true;
if (NeedsRefcounting(var_)) {
- if (has_interface<PPB_Var_1_0>()) {
- needs_release_ = true;
+ if (has_interface<PPB_Var_1_0>())
get_interface<PPB_Var_1_0>()->AddRef(var_);
- } else {
+ else
var_.type = PP_VARTYPE_NULL;
- needs_release_ = false;
- }
- } else {
- needs_release_ = false;
}
}
Var::~Var() {
- if (needs_release_ && has_interface<PPB_Var_1_0>())
+ if (NeedsRefcounting(var_) &&
+ is_managed_ &&
+ has_interface<PPB_Var_1_0>())
get_interface<PPB_Var_1_0>()->Release(var_);
}
@@ -130,16 +128,14 @@ Var& Var::operator=(const Var& other) {
// Be careful to keep the ref alive for cases where we're assigning an
// object to itself by addrefing the new one before releasing the old one.
- bool old_needs_release = needs_release_;
+ bool old_is_managed = is_managed_;
+ is_managed_ = true;
if (NeedsRefcounting(other.var_)) {
// Assume we already has_interface<PPB_Var_1_0> for refcounted vars or else
// we couldn't have created them in the first place.
- needs_release_ = true;
get_interface<PPB_Var_1_0>()->AddRef(other.var_);
- } else {
- needs_release_ = false;
}
- if (old_needs_release)
+ if (NeedsRefcounting(var_) && old_is_managed)
get_interface<PPB_Var_1_0>()->Release(var_);
var_ = other.var_;
« no previous file with comments | « ppapi/cpp/var.h ('k') | ppapi/cpp/var_array_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698