mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
AK: Fix leak in Optional(Optional&&)
We were *copying* the other Optional's value and then marking it as not having a value. This prevented us from ever destroying the original.
This commit is contained in:
parent
9553ecfe01
commit
151e6a1818
Notes:
sideshowbarker
2024-07-19 12:51:54 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/151e6a18185
@ -29,7 +29,7 @@ public:
|
||||
: m_has_value(other.m_has_value)
|
||||
{
|
||||
if (m_has_value) {
|
||||
new (&m_storage) T(move(other.value_without_consume_state()));
|
||||
new (&m_storage) T(other.release_value());
|
||||
other.m_has_value = false;
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,17 @@ TEST_CASE(move_optional)
|
||||
EXPECT_EQ(x.has_value(), false);
|
||||
}
|
||||
|
||||
TEST_CASE(optional_leak_1)
|
||||
{
|
||||
struct Structure {
|
||||
Optional<String> str;
|
||||
};
|
||||
|
||||
// This used to leak, it does not anymore.
|
||||
Vector<Structure> vec;
|
||||
vec.append({ "foo" });
|
||||
EXPECT_EQ(vec[0].str.has_value(), true);
|
||||
EXPECT_EQ(vec[0].str.value(), "foo");
|
||||
}
|
||||
|
||||
TEST_MAIN(Optional)
|
||||
|
Loading…
Reference in New Issue
Block a user