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

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: done 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
Index: ppapi/cpp/var.cc
diff --git a/ppapi/cpp/var.cc b/ppapi/cpp/var.cc
index 3e76593bd2763ff5fec11c110bef977ea0a8dc1a..9560f747bb27d299be8627177588f3c7d06b8c60 100644
--- a/ppapi/cpp/var.cc
+++ b/ppapi/cpp/var.cc
@@ -59,34 +59,34 @@ 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;
+ needs_release_ = true;
Takashi Toyoshima 2012/09/07 17:18:27 NeedsRefcounting() tell us if the PP_Var requires
dmichael (off chromium) 2012/09/07 18:36:58 Currently, it only tells you if the Var's *type* r
Takashi Toyoshima 2012/09/10 13:21:27 I meant that we can change the meaning of |needs_r
}
Var::Var(Null) {
memset(&var_, 0, sizeof(var_));
var_.type = PP_VARTYPE_NULL;
- needs_release_ = false;
+ needs_release_ = true;
}
Var::Var(bool b) {
var_.type = PP_VARTYPE_BOOL;
var_.padding = 0;
var_.value.as_bool = PP_FromBool(b);
- needs_release_ = false;
+ needs_release_ = true;
}
Var::Var(int32_t i) {
var_.type = PP_VARTYPE_INT32;
var_.padding = 0;
var_.value.as_int = i;
- needs_release_ = false;
+ needs_release_ = true;
}
Var::Var(double d) {
var_.type = PP_VARTYPE_DOUBLE;
var_.padding = 0;
var_.value.as_double = d;
- needs_release_ = false;
+ needs_release_ = true;
}
Var::Var(const char* utf8_str) {
@@ -103,21 +103,17 @@ Var::Var(const std::string& utf8_str) {
Var::Var(const Var& other) {
var_ = other.var_;
+ needs_release_ = 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 (needs_release_ && NeedsRefcounting(var_) && has_interface<PPB_Var_1_0>())
Takashi Toyoshima 2012/09/07 17:18:27 PP_Var leaked when PP_Var was updated after constr
get_interface<PPB_Var_1_0>()->Release(var_);
}
@@ -131,15 +127,13 @@ 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_;
+ needs_release_ = 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 (old_needs_release && NeedsRefcounting(var_))
get_interface<PPB_Var_1_0>()->Release(var_);
var_ = other.var_;

Powered by Google App Engine
This is Rietveld 408576698