Commit 6c629dc3 by Nicolas Capens Committed by Nicolas Capens

Fix potential null pointer dereference.

When the compiler does not perform return value optimization, the LockPtr<> destructor of the temporary object is called after the move constructor has set the Lock to null, thus causing a null pointer dereference in the destructor. This can be replicated using the -fno-elide-constructors build flag. Change-Id: Ie00c3f93364fdf78ea1993469b9a606b3c87ebdc Reviewed-on: https://chromium-review.googlesource.com/486985Reviewed-by: 's avatarJim Stichnoth <stichnot@chromium.org>
parent 47b6ba6d
......@@ -398,7 +398,10 @@ public:
Other.Value = nullptr;
Other.Lock = nullptr;
}
~LockedPtr() { Lock->unlock(); }
~LockedPtr() {
if (Lock != nullptr)
Lock->unlock();
}
T *operator->() const { return Value; }
T &operator*() const { return *Value; }
T *get() { return Value; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment