xiangaodielian / bullet

Automatically exported from code.google.com/p/bullet
Other
0 stars 0 forks source link

memory leak after calling btPolyhedralConvexShape::initializePolyhedralFeatures() #623

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Simply call btPolyhedralConvexShape::initializePolyhedralFeatures() on an 
object with a class derived from btPolyhedralConvexShape
2.
3.

What is the expected output? What do you see instead?

In my project the Microsoft leak detection is turned on. When I call 
initializePolyhedralFeatures in my program, after exiting my program, Visual 
Studio dumps memory lekas.

What version of the product are you using? On what operating system?

I use 2.79 on windows but probably it will be the same with 2.80, as well.

Please provide any additional information below.

The memory leaks happen probably because when freeing m_polyhedron member of 
btPolyhedralConvexShape the destructor of btConvexPolyhedron is not called.

It is a code snippet from btPolyhedralConvexShape.cpp :

btPolyhedralConvexShape::~btPolyhedralConvexShape()
{
    if (m_polyhedron)
    {
        btAlignedFree(m_polyhedron);
    }
}

bool    btPolyhedralConvexShape::initializePolyhedralFeatures()
{

    if (m_polyhedron)
        btAlignedFree(m_polyhedron);

    void* mem = btAlignedAlloc(sizeof(btConvexPolyhedron),16);
    m_polyhedron = new (mem) btConvexPolyhedron;

Probably the solution is this:

btPolyhedralConvexShape::~btPolyhedralConvexShape()
{
    if (m_polyhedron)
    {
        m_polyhedron->~btConvexPolyhedron();
        btAlignedFree(m_polyhedron);
    }
}

bool    btPolyhedralConvexShape::initializePolyhedralFeatures()
{

    if (m_polyhedron)
    {
        m_polyhedron->~btConvexPolyhedron();
        btAlignedFree(m_polyhedron);
    }

    void* mem = btAlignedAlloc(sizeof(btConvexPolyhedron),16);
    m_polyhedron = new (mem) btConvexPolyhedron;

Original issue reported on code.google.com by gmlgml...@gmail.com on 1 May 2012 at 11:48

GoogleCodeExporter commented 9 years ago
I forgot, that when I apply the recommended changes, the dumped leaks disappear 
from the Visual Studio output

Original comment by gmlgml...@gmail.com on 1 May 2012 at 11:52

GoogleCodeExporter commented 9 years ago
Also experiencing this in SuperTuxKart, added patch for the sake of convenience.

Original comment by Ward.Muy...@gmail.com on 17 Jul 2012 at 5:31

Attachments:

GoogleCodeExporter commented 9 years ago
Good point, I applied the patch in latest trunk:
https://code.google.com/p/bullet/source/detail?r=2555

Thanks for your help!

Original comment by erwin.coumans on 8 Sep 2012 at 7:44