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

Unified Diff: ppapi/cpp/var.cc

Issue 7511026: Fix some egregious bugs in Var. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
===================================================================
--- ppapi/cpp/var.cc (revision 95308)
+++ ppapi/cpp/var.cc (working copy)
@@ -117,20 +117,21 @@
}
Var& Var::operator=(const Var& other) {
- if (needs_release_ && has_interface<PPB_Var>())
- get_interface<PPB_Var>()->Release(var_);
- var_ = other.var_;
- if (NeedsRefcounting(var_)) {
- if (has_interface<PPB_Var>()) {
- needs_release_ = true;
- get_interface<PPB_Var>()->AddRef(var_);
- } else {
- var_.type = PP_VARTYPE_NULL;
- needs_release_ = false;
- }
+ // 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_;
+ if (NeedsRefcounting(other.var_)) {
+ // Assume we already has_interface<PPB_Var> for refcounted vars or else we
+ // couldn't have created them in the first place.
+ needs_release_ = true;
+ get_interface<PPB_Var>()->AddRef(other.var_);
} else {
needs_release_ = false;
}
+ if (old_needs_release)
+ get_interface<PPB_Var>()->Release(var_);
+
+ var_ = other.var_;
return *this;
}
« ppapi/cpp/var.h ('K') | « ppapi/cpp/var.h ('k') | ppapi/tests/test_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698