Prevent UB if a WeakPtr to an already-destroyed object is dereferenced.
If a WeakPtr references an already-destroyed object, operator-> and operator* end up simply dereferencing nullptr. However, dereferencing nullptr is undefined behavior and can be optimized in surprising ways by compilers. To prevent this from happening, add a defence of last resort and CHECK that the WeakPtr is still valid. Based on https://crrev.com/bbb64b5c69
This commit is contained in:
parent
0b7840ab2f
commit
d2c884da86
|
@ -250,11 +250,11 @@ class WeakPtr : public cef_internal::WeakPtrBase {
|
|||
T* get() const { return ref_.is_valid() ? ptr_ : NULL; }
|
||||
|
||||
T& operator*() const {
|
||||
DCHECK(get() != NULL);
|
||||
CHECK(ref_.is_valid());
|
||||
return *get();
|
||||
}
|
||||
T* operator->() const {
|
||||
DCHECK(get() != NULL);
|
||||
CHECK(ref_.is_valid());
|
||||
return get();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue