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 ...@@ -45,6 +45,19 @@ class RefCountObjectNoID : angle::NonCopyable
protected: protected:
virtual ~RefCountObjectNoID() { ASSERT(mRefCount == 0); } 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; mutable std::size_t mRefCount;
}; };
...@@ -58,17 +71,7 @@ class RefCountObject : RefCountObjectNoID ...@@ -58,17 +71,7 @@ class RefCountObject : RefCountObjectNoID
GLuint id() const { return mId; } GLuint id() const { return mId; }
// A specialized release method for objects which need a destroy context. using RefCountObjectNoID::release;
void release(const gl::Context *context)
{
ASSERT(mRefCount > 0);
if (--mRefCount == 0)
{
onDestroy(context);
delete this;
}
}
using RefCountObjectNoID::addRef; using RefCountObjectNoID::addRef;
using RefCountObjectNoID::getRefCount; using RefCountObjectNoID::getRefCount;
...@@ -76,8 +79,6 @@ class RefCountObject : RefCountObjectNoID ...@@ -76,8 +79,6 @@ class RefCountObject : RefCountObjectNoID
~RefCountObject() override {} ~RefCountObject() override {}
private: private:
template <class ObjectType>
friend class BindingPointer;
GLuint mId; GLuint mId;
}; };
...@@ -112,9 +113,9 @@ class BindingPointer ...@@ -112,9 +113,9 @@ class BindingPointer
virtual void set(const Context *context, ObjectType *newObject) virtual void set(const Context *context, ObjectType *newObject)
{ {
// addRef first in case newObject == mObject and this is the last reference to it. // 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) if (mObject != nullptr)
reinterpret_cast<RefCountObject *>(mObject)->release(context); reinterpret_cast<RefCountObjectNoID *>(mObject)->release(context);
mObject = newObject; 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