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:
parent
82398e5724
commit
6aa334767f
2 changed files with 25 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue