Index: mojo/public/cpp/system/core.h |
diff --git a/mojo/public/cpp/system/core.h b/mojo/public/cpp/system/core.h |
index 2b1caa914a4b69770a9e632dbad6e01564bb5229..13be3eb3f746c39d47c67cbca0538efbf5ba90e2 100644 |
--- a/mojo/public/cpp/system/core.h |
+++ b/mojo/public/cpp/system/core.h |
@@ -107,7 +107,10 @@ class ScopedHandleBase { |
// Move-only constructor and operator=. |
ScopedHandleBase(RValue other) : handle_(other.object->release()) {} |
ScopedHandleBase& operator=(RValue other) { |
- handle_ = other.object->release(); |
+ if (other.object != this) { |
+ CloseIfNecessary(); |
+ handle_ = other.object->release(); |
+ } |
return *this; |
} |