mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Fix unintentional state transfer in DetachToUserFree (fixes issue #3309)
Calling DetachToUserFree() on a CefString holding a reference should copy the value instead of transferring ownership. A new `StringTest.Ownership` test has been added for this behavior.
This commit is contained in:
@ -584,10 +584,16 @@ class CefStringBase {
|
||||
return NULL;
|
||||
|
||||
userfree_struct_type str = traits::userfree_alloc();
|
||||
memcpy(str, string_, sizeof(struct_type));
|
||||
if (owner_) {
|
||||
// Transfer ownership of the data to |str|.
|
||||
memcpy(str, string_, sizeof(struct_type));
|
||||
// Free this class' structure but not the data.
|
||||
memset(string_, 0, sizeof(struct_type));
|
||||
} else {
|
||||
// Copy the data to |str|.
|
||||
traits::set(string_->str, string_->length, str, /*copy=*/true);
|
||||
}
|
||||
|
||||
// Free this class' structure but not the data.
|
||||
memset(string_, 0, sizeof(struct_type));
|
||||
ClearAndFree();
|
||||
|
||||
return str;
|
||||
|
Reference in New Issue
Block a user