1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

AK: Ensure assigned-to Strings are dereferenced if needed

If we assign to an existing non-short string, we must dereference its
StringData object to prevent leaking that data.
This commit is contained in:
Timothy Flynn 2023-11-28 08:59:47 -05:00 committed by Andreas Kling
parent 82398e5724
commit 6aa334767f
2 changed files with 25 additions and 0 deletions

View file

@ -215,10 +215,15 @@ String& String::operator=(String&& other)
String& String::operator=(String const& other)
{
if (&other != this) {
if (!is_short_string())
m_data->unref();
m_data = other.m_data;
if (!is_short_string())
m_data->ref();
}
return *this;
}