Skip to content

Commit

Permalink
Fix JSValue memory leak in move constructor (#7868)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoroz committed May 28, 2021
1 parent 8209eb5 commit 3bfe8e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix JSValue memory leak in move constructor",
"packageName": "react-native-windows",
"email": "vmorozov@microsoft.com",
"dependentChangeType": "patch"
}
9 changes: 4 additions & 5 deletions vnext/Microsoft.ReactNative.Cxx/JSValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ void JSValueArray::WriteTo(IJSValueWriter const &writer) const noexcept {
JSValue::JSValue(JSValue &&other) noexcept : m_type{other.m_type} {
switch (m_type) {
case JSValueType::Object:
new (&m_object) JSValueObject(std::move(other.m_object));
new (std::addressof(m_object)) JSValueObject(std::move(other.m_object));
break;
case JSValueType::Array:
new (&m_array) JSValueArray(std::move(other.m_array));
new (std::addressof(m_array)) JSValueArray(std::move(other.m_array));
break;
case JSValueType::String:
new (&m_string) std::string(std::move(other.m_string));
new (std::addressof(m_string)) std::string(std::move(other.m_string));
break;
case JSValueType::Boolean:
m_bool = other.m_bool;
Expand All @@ -458,8 +458,7 @@ JSValue::JSValue(JSValue &&other) noexcept : m_type{other.m_type} {
break;
}

other.m_type = JSValueType::Null;
other.m_int64 = 0;
other.~JSValue();
}
#pragma warning(pop)

Expand Down

0 comments on commit 3bfe8e1

Please sign in to comment.