CefStringBase::DetachToUserFree modifies data it does not own
userfree_struct_type DetachToUserFree() { if (empty()) return NULL; userfree_struct_type str = traits::userfree_alloc(); memcpy(str, string_, sizeof(struct_type)); // Free this class' structure but not the data. memset(string_, 0, sizeof(struct_type)); ClearAndFree(); return str; }
memset(string_, 0, sizeof(struct_type));
This line fill zeroes tostring_
, which it may not own.
this is the reason why CefRequestContext::GetCachePath() behaves correctly only at first call, and return empty string at later calls.
Comments (6)
-
-
I think the correct (general) solution is for
DetachToUserFree
to copy strings instead of transferring ownership whenowner_==false
. -
- changed status to resolved
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.→ <<cset 4921dc22135e>>
-
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.→ <<cset e56440898e62>>
-
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.→ <<cset c36c371f68c0>>
-
reporter Thank you for fixing the issue so quickly.
- Log in to comment
I believe the problem is this:
Which uses this CefString constructor:
So the CefString returned from GetCachePath references
config_.settings.cache_path
instead of making a copy. Then, the call toDetachToUserFree
unintentionally clearsconfig_.settings.cache_path
.