Title: [242613] trunk/Source/_javascript_Core
- Revision
- 242613
- Author
- [email protected]
- Date
- 2019-03-07 14:41:17 -0800 (Thu, 07 Mar 2019)
Log Message
CompactVariableMap::Handle's copy operator= leaks the previous data
https://bugs.webkit.org/show_bug.cgi?id=195398
Reviewed by Yusuke Suzuki.
The copy constructor was just assigning |this| to the new value,
forgetting to decrement the ref count of the thing pointed to by
the |this| handle. Based on Yusuke's suggestion, this patch refactors
the move constructor, move operator=, and copy operator= to use the
swap() primitive and the copy constructor primitive.
* parser/VariableEnvironment.cpp:
(JSC::CompactVariableMap::Handle::Handle):
(JSC::CompactVariableMap::Handle::swap):
(JSC::CompactVariableMap::Handle::operator=): Deleted.
* parser/VariableEnvironment.h:
(JSC::CompactVariableMap::Handle::Handle):
(JSC::CompactVariableMap::Handle::operator=):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (242612 => 242613)
--- trunk/Source/_javascript_Core/ChangeLog 2019-03-07 22:17:40 UTC (rev 242612)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-03-07 22:41:17 UTC (rev 242613)
@@ -1,3 +1,24 @@
+2019-03-07 Saam Barati <[email protected]>
+
+ CompactVariableMap::Handle's copy operator= leaks the previous data
+ https://bugs.webkit.org/show_bug.cgi?id=195398
+
+ Reviewed by Yusuke Suzuki.
+
+ The copy constructor was just assigning |this| to the new value,
+ forgetting to decrement the ref count of the thing pointed to by
+ the |this| handle. Based on Yusuke's suggestion, this patch refactors
+ the move constructor, move operator=, and copy operator= to use the
+ swap() primitive and the copy constructor primitive.
+
+ * parser/VariableEnvironment.cpp:
+ (JSC::CompactVariableMap::Handle::Handle):
+ (JSC::CompactVariableMap::Handle::swap):
+ (JSC::CompactVariableMap::Handle::operator=): Deleted.
+ * parser/VariableEnvironment.h:
+ (JSC::CompactVariableMap::Handle::Handle):
+ (JSC::CompactVariableMap::Handle::operator=):
+
2019-03-07 Tadeu Zagallo <[email protected]>
Lazily decode cached bytecode
Modified: trunk/Source/_javascript_Core/parser/VariableEnvironment.cpp (242612 => 242613)
--- trunk/Source/_javascript_Core/parser/VariableEnvironment.cpp 2019-03-07 22:17:40 UTC (rev 242612)
+++ trunk/Source/_javascript_Core/parser/VariableEnvironment.cpp 2019-03-07 22:41:17 UTC (rev 242613)
@@ -193,26 +193,20 @@
}
CompactVariableMap::Handle::Handle(const CompactVariableMap::Handle& other)
+ : m_environment(other.m_environment)
+ , m_map(other.m_map)
{
- *this = other;
+ if (m_map) {
+ auto iter = m_map->m_map.find(CompactVariableMapKey { *m_environment });
+ RELEASE_ASSERT(iter != m_map->m_map.end());
+ ++iter->value;
+ }
}
-CompactVariableMap::Handle& CompactVariableMap::Handle::operator=(const Handle& other)
-{
- m_map = other.m_map;
- m_environment = other.m_environment;
-
- if (!m_map) {
- ASSERT(!m_environment);
- // This happens if `other` were moved into a different handle.
- return *this;
- }
-
- auto iter = m_map->m_map.find(CompactVariableMapKey { *m_environment });
- RELEASE_ASSERT(iter != m_map->m_map.end());
- ++iter->value;
-
- return *this;
+CompactVariableMap::Handle::Handle(CompactVariableEnvironment& environment, CompactVariableMap& map)
+ : m_environment(&environment)
+ , m_map(&map)
+{
}
} // namespace JSC
Modified: trunk/Source/_javascript_Core/parser/VariableEnvironment.h (242612 => 242613)
--- trunk/Source/_javascript_Core/parser/VariableEnvironment.h 2019-03-07 22:17:40 UTC (rev 242612)
+++ trunk/Source/_javascript_Core/parser/VariableEnvironment.h 2019-03-07 22:41:17 UTC (rev 242613)
@@ -214,21 +214,26 @@
public:
Handle() = default;
- Handle(CompactVariableEnvironment& environment, CompactVariableMap& map)
- : m_environment(&environment)
- , m_map(&map)
- { }
+ Handle(CompactVariableEnvironment&, CompactVariableMap&);
+
Handle(Handle&& other)
- : m_environment(other.m_environment)
- , m_map(WTFMove(other.m_map))
{
- RELEASE_ASSERT(!!m_environment == !!m_map);
- ASSERT(!other.m_map);
- other.m_environment = nullptr;
+ swap(other);
}
+ Handle& operator=(Handle&& other)
+ {
+ Handle handle(WTFMove(other));
+ swap(handle);
+ return *this;
+ }
Handle(const Handle&);
- Handle& operator=(const Handle&);
+ Handle& operator=(const Handle& other)
+ {
+ Handle handle(other);
+ swap(handle);
+ return *this;
+ }
~Handle();
@@ -240,6 +245,12 @@
}
private:
+ void swap(Handle& other)
+ {
+ std::swap(other.m_environment, m_environment);
+ std::swap(other.m_map, m_map);
+ }
+
CompactVariableEnvironment* m_environment { nullptr };
RefPtr<CompactVariableMap> m_map;
};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes