From 0d5552851bdaee02aa32d6a82d63c8d399a033be Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Thu, 27 Aug 2020 23:40:25 -0500 Subject: [PATCH] Memory Leak Fixed - SGTexturedTriangleBin Reclaimed 42,560 bytes in 280 blocks --- simgear/scene/tgdb/SGTexturedTriangleBin.hxx | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx index 1b363d7b..60ad5286 100644 --- a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx +++ b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx @@ -430,13 +430,12 @@ public: return 0; // FIXME: do not include all values here ... - osg::Vec3Array* vertices = new osg::Vec3Array; - osg::Vec3Array* normals = new osg::Vec3Array; - osg::Vec2Array* priTexCoords = new osg::Vec2Array; - // REVIEW: Memory Leak - 42,560 bytes in 280 blocks are definitely lost - osg::Vec2Array* secTexCoords = new osg::Vec2Array; + osg::ref_ptr vertices = new osg::Vec3Array; + osg::ref_ptr normals = new osg::Vec3Array; + osg::ref_ptr priTexCoords = new osg::Vec2Array; + osg::ref_ptr secTexCoords = new osg::Vec2Array; - osg::Vec4Array* colors = new osg::Vec4Array; + osg::ref_ptr colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1, 1, 1, 1)); osg::Geometry* geometry = new osg::Geometry; @@ -446,18 +445,18 @@ public: } geometry->setDataVariance(osg::Object::STATIC); - geometry->setVertexArray(vertices); + geometry->setVertexArray(vertices.get()); if (include_norms) { - geometry->setNormalArray(normals); + geometry->setNormalArray(normals.get()); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); } - geometry->setColorArray(colors); + geometry->setColorArray(colors.get()); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); if ( has_sec_tcs ) { - geometry->setTexCoordArray(0, priTexCoords); - geometry->setTexCoordArray(1, secTexCoords); + geometry->setTexCoordArray(0, priTexCoords.get()); + geometry->setTexCoordArray(1, secTexCoords.get()); } else { - geometry->setTexCoordArray(0, priTexCoords); + geometry->setTexCoordArray(0, priTexCoords.get()); } const unsigned invalid = ~unsigned(0);