From 0b3abacb3ce8d6da5396eeb0f29128f6b9c33354 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 7 Feb 2015 14:15:05 +0100 Subject: [PATCH] Fix possible memory leaks --- examples/common/glfw/CMakeLists.txt | 2 -- src/body/CollisionBody.cpp | 8 ++++---- src/body/RigidBody.cpp | 4 ++-- src/collision/CollisionDetection.cpp | 12 ++++++------ src/engine/CollisionWorld.cpp | 4 ++-- src/engine/ContactManifold.cpp | 6 +++--- src/engine/DynamicsWorld.cpp | 8 ++++---- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/common/glfw/CMakeLists.txt b/examples/common/glfw/CMakeLists.txt index 389f3bdd..731f09f7 100644 --- a/examples/common/glfw/CMakeLists.txt +++ b/examples/common/glfw/CMakeLists.txt @@ -490,9 +490,7 @@ endif() #-------------------------------------------------------------------- # Export GLFW library dependencies #-------------------------------------------------------------------- -MESSAGE(BEFORE ${glfw_LIBRARIES}) set(GLFW_LIBRARIES ${glfw_LIBRARIES} CACHE STRING "Dependencies of GLFW") -MESSAGE(FINAL ${GLFW_LIBRARIES}) foreach(arg ${glfw_PKG_DEPS}) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} ${arg}") endforeach() diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index a310ab26..c9ab7a91 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -107,7 +107,7 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { } mWorld.removeCollisionShape(proxyShape->mCollisionShape); - current->ProxyShape::~ProxyShape(); + current->~ProxyShape(); mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape)); mNbCollisionShapes--; assert(mNbCollisionShapes >= 0); @@ -129,7 +129,7 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { } mWorld.removeCollisionShape(proxyShape->mCollisionShape); - elementToRemove->ProxyShape::~ProxyShape(); + elementToRemove->~ProxyShape(); mWorld.mMemoryAllocator.release(elementToRemove, sizeof(ProxyShape)); mNbCollisionShapes--; return; @@ -160,7 +160,7 @@ void CollisionBody::removeAllCollisionShapes() { } mWorld.removeCollisionShape(current->mCollisionShape); - current->ProxyShape::~ProxyShape(); + current->~ProxyShape(); mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape)); // Get the next element in the list @@ -179,7 +179,7 @@ void CollisionBody::resetContactManifoldsList() { ContactManifoldListElement* nextElement = currentElement->next; // Delete the current element - currentElement->ContactManifoldListElement::~ContactManifoldListElement(); + currentElement->~ContactManifoldListElement(); mWorld.mMemoryAllocator.release(currentElement, sizeof(ContactManifoldListElement)); currentElement = nextElement; diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 9dcd2c13..2cf2f0cd 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -147,7 +147,7 @@ void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, cons if (mJointsList->joint == joint) { // If the first element is the one to remove JointListElement* elementToRemove = mJointsList; mJointsList = elementToRemove->next; - elementToRemove->JointListElement::~JointListElement(); + elementToRemove->~JointListElement(); memoryAllocator.release(elementToRemove, sizeof(JointListElement)); } else { // If the element to remove is not the first one in the list @@ -156,7 +156,7 @@ void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, cons if (currentElement->next->joint == joint) { JointListElement* elementToRemove = currentElement->next; currentElement->next = elementToRemove->next; - elementToRemove->JointListElement::~JointListElement(); + elementToRemove->~JointListElement(); memoryAllocator.release(elementToRemove, sizeof(JointListElement)); break; } diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 7885bbca..0c17520f 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -133,7 +133,7 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac if (callback != NULL) callback->notifyContact(*contactInfo); // Delete and remove the contact info from the memory allocator - contactInfo->ContactPointInfo::~ContactPointInfo(); + contactInfo->~ContactPointInfo(); mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); } } @@ -182,7 +182,7 @@ void CollisionDetection::computeNarrowPhase() { ++it; // Destroy the overlapping pair - itToRemove->second->OverlappingPair::~OverlappingPair(); + itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); mOverlappingPairs.erase(itToRemove); continue; @@ -233,7 +233,7 @@ void CollisionDetection::computeNarrowPhase() { if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(*contactInfo); // Delete and remove the contact info from the memory allocator - contactInfo->ContactPointInfo::~ContactPointInfo(); + contactInfo->~ContactPointInfo(); mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); } } @@ -288,7 +288,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call ++it; // Destroy the overlapping pair - itToRemove->second->OverlappingPair::~OverlappingPair(); + itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); mOverlappingPairs.erase(itToRemove); continue; @@ -331,7 +331,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call if (callback != NULL) callback->notifyContact(*contactInfo); // Delete and remove the contact info from the memory allocator - contactInfo->ContactPointInfo::~ContactPointInfo(); + contactInfo->~ContactPointInfo(); mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); } } @@ -381,7 +381,7 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) { ++it; // Destroy the overlapping pair - itToRemove->second->OverlappingPair::~OverlappingPair(); + itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); mOverlappingPairs.erase(itToRemove); } diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index a0813339..c3747134 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -76,7 +76,7 @@ void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) { mFreeBodiesIDs.push_back(collisionBody->getID()); // Call the destructor of the collision body - collisionBody->CollisionBody::~CollisionBody(); + collisionBody->~CollisionBody(); // Remove the collision body from the list of bodies mBodies.erase(collisionBody); @@ -159,7 +159,7 @@ void CollisionWorld::removeCollisionShape(CollisionShape* collisionShape) { size_t nbBytesShape = collisionShape->getSizeInBytes(); // Call the destructor of the collision shape - collisionShape->CollisionShape::~CollisionShape(); + collisionShape->~CollisionShape(); // Deallocate the memory used by the collision shape mMemoryAllocator.release(collisionShape, nbBytesShape); diff --git a/src/engine/ContactManifold.cpp b/src/engine/ContactManifold.cpp index 4249afe2..89dd2a38 100644 --- a/src/engine/ContactManifold.cpp +++ b/src/engine/ContactManifold.cpp @@ -56,7 +56,7 @@ void ContactManifold::addContactPoint(ContactPoint* contact) { if (distance <= PERSISTENT_CONTACT_DIST_THRESHOLD*PERSISTENT_CONTACT_DIST_THRESHOLD) { // Delete the new contact - contact->ContactPoint::~ContactPoint(); + contact->~ContactPoint(); mMemoryAllocator.release(contact, sizeof(ContactPoint)); //removeContact(i); @@ -84,7 +84,7 @@ void ContactManifold::removeContactPoint(uint index) { // Call the destructor explicitly and tell the memory allocator that // the corresponding memory block is now free - mContactPoints[index]->ContactPoint::~ContactPoint(); + mContactPoints[index]->~ContactPoint(); mMemoryAllocator.release(mContactPoints[index], sizeof(ContactPoint)); // If we don't remove the last index @@ -253,7 +253,7 @@ void ContactManifold::clear() { // Call the destructor explicitly and tell the memory allocator that // the corresponding memory block is now free - mContactPoints[i]->ContactPoint::~ContactPoint(); + mContactPoints[i]->~ContactPoint(); mMemoryAllocator.release(mContactPoints[i], sizeof(ContactPoint)); } mNbContactPoints = 0; diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 01792b54..01660643 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -60,7 +60,7 @@ DynamicsWorld::~DynamicsWorld() { for (uint i=0; iIsland::~Island(); + mIslands[i]->~Island(); // Release the allocated memory for the island mMemoryAllocator.release(mIslands[i], sizeof(Island)); @@ -497,7 +497,7 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) { rigidBody->resetContactManifoldsList(); // Call the destructor of the rigid body - rigidBody->RigidBody::~RigidBody(); + rigidBody->~RigidBody(); // Remove the rigid body from the list of rigid bodies mBodies.erase(rigidBody); @@ -602,7 +602,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) { size_t nbBytes = joint->getSizeInBytes(); // Call the destructor of the joint - joint->Joint::~Joint(); + joint->~Joint(); // Release the allocated memory mMemoryAllocator.release(joint, nbBytes); @@ -643,7 +643,7 @@ void DynamicsWorld::computeIslands() { for (uint i=0; iIsland::~Island(); + mIslands[i]->~Island(); // Release the allocated memory for the island mMemoryAllocator.release(mIslands[i], sizeof(Island));