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
commit 6aa334767f
Notes: sideshowbarker 2024-07-17 07:20:49 +09:00
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;
}