Commit 32b7e237 by Peter Collingbourne Committed by Commit Bot

Fix bad casts in BindingPointer::set.

The object owned by the BindingPointer does not necessarily derive from RefCountObject; it could also just derive from RefCountObjectNoID (e.g. Compiler). Found with Clang's CFI bad cast checker. BUG=chromium:507755 Change-Id: I7e431746b2783e2fc0f2d347a4a27bd60da18473 Reviewed-on: https://chromium-review.googlesource.com/667218Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent eccd7ece
......@@ -45,6 +45,19 @@ class RefCountObjectNoID : angle::NonCopyable
protected:
virtual ~RefCountObjectNoID() { ASSERT(mRefCount == 0); }
// A specialized release method for objects which need a destroy context.
void release(const gl::Context *context)
{
ASSERT(mRefCount > 0);
if (--mRefCount == 0)
{
onDestroy(context);
delete this;
}
}
template <class ObjectType>
friend class BindingPointer;
mutable std::size_t mRefCount;
};
......@@ -58,17 +71,7 @@ class RefCountObject : RefCountObjectNoID
GLuint id() const { return mId; }
// A specialized release method for objects which need a destroy context.
void release(const gl::Context *context)
{
ASSERT(mRefCount > 0);
if (--mRefCount == 0)
{
onDestroy(context);
delete this;
}
}
using RefCountObjectNoID::release;
using RefCountObjectNoID::addRef;
using RefCountObjectNoID::getRefCount;
......@@ -76,8 +79,6 @@ class RefCountObject : RefCountObjectNoID
~RefCountObject() override {}
private:
template <class ObjectType>
friend class BindingPointer;
GLuint mId;
};
......@@ -112,9 +113,9 @@ class BindingPointer
virtual void set(const Context *context, ObjectType *newObject)
{
// addRef first in case newObject == mObject and this is the last reference to it.
if (newObject != nullptr) reinterpret_cast<const RefCountObject*>(newObject)->addRef();
if (newObject != nullptr) reinterpret_cast<const RefCountObjectNoID*>(newObject)->addRef();
if (mObject != nullptr)
reinterpret_cast<RefCountObject *>(mObject)->release(context);
reinterpret_cast<RefCountObjectNoID *>(mObject)->release(context);
mObject = newObject;
}
......
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