Addressed a number of memory leaks identified in unit tests by asan
parent
29e46e4bb8
commit
1eb7eceddf
|
@ -82,6 +82,20 @@ static const aiImporterDesc desc = {
|
|||
|
||||
//#define DEBUG_B3D
|
||||
|
||||
template<typename T>
|
||||
void DeleteAllBarePointers(std::vector<T>& x)
|
||||
{
|
||||
for(auto p : x)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
B3DImporter::~B3DImporter()
|
||||
{
|
||||
DeleteAllBarePointers(_animations);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
|
||||
|
||||
|
@ -558,13 +572,19 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
|
|||
void B3DImporter::ReadBB3D( aiScene *scene ){
|
||||
|
||||
_textures.clear();
|
||||
|
||||
_materials.clear();
|
||||
|
||||
_vertices.clear();
|
||||
|
||||
_meshes.clear();
|
||||
|
||||
DeleteAllBarePointers(_nodes);
|
||||
_nodes.clear();
|
||||
|
||||
_nodeAnims.clear();
|
||||
|
||||
DeleteAllBarePointers(_animations);
|
||||
_animations.clear();
|
||||
|
||||
string t=ReadChunk();
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace Assimp{
|
|||
|
||||
class B3DImporter : public BaseImporter{
|
||||
public:
|
||||
B3DImporter() = default;
|
||||
virtual ~B3DImporter();
|
||||
|
||||
virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||
|
||||
|
|
|
@ -634,7 +634,7 @@ void PretransformVertices::Execute( aiScene* pScene)
|
|||
aiNode* newRoot = new aiNode();
|
||||
newRoot->mName = pScene->mRootNode->mName;
|
||||
delete pScene->mRootNode;
|
||||
pScene->mRootNode = new aiNode();
|
||||
pScene->mRootNode = newRoot;
|
||||
|
||||
if (1 == pScene->mNumMeshes && !pScene->mNumLights && !pScene->mNumCameras)
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
static aiScene *createDefaultTestModel( float &opacity ) {
|
||||
aiScene *scene( new aiScene );
|
||||
scene->mNumMaterials = 1;
|
||||
scene->mMaterials = new aiMaterial*;
|
||||
scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
|
||||
scene->mMaterials[ 0 ] = new aiMaterial;
|
||||
aiColor3D color( 1, 0, 0 );
|
||||
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) );
|
||||
|
@ -70,7 +70,7 @@ public:
|
|||
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) );
|
||||
|
||||
scene->mNumMeshes = 1;
|
||||
scene->mMeshes = new aiMesh*;
|
||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes];
|
||||
scene->mMeshes[ 0 ] = new aiMesh;
|
||||
scene->mMeshes[ 0 ]->mMaterialIndex = 0;
|
||||
scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 );
|
||||
scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 );
|
||||
scene->mMeshes[ 0 ]->mNumFaces = 1;
|
||||
scene->mMeshes[ 0 ]->mFaces = new aiFace;
|
||||
scene->mMeshes[ 0 ]->mFaces = new aiFace[scene->mMeshes[ 0 ]->mNumFaces];
|
||||
scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3;
|
||||
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ];
|
||||
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0;
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
|
||||
scene->mRootNode = new aiNode;
|
||||
scene->mRootNode->mNumMeshes = 1;
|
||||
scene->mRootNode->mMeshes = new unsigned int( 0 );
|
||||
scene->mRootNode->mMeshes = new unsigned int[scene->mRootNode->mNumMeshes]{ 0 };
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ TEST_F( utIssues, OpacityBugWhenExporting_727 ) {
|
|||
EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) );
|
||||
EXPECT_EQ( opacity, newOpacity );
|
||||
}
|
||||
delete scene;
|
||||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
|
|
|
@ -237,6 +237,15 @@ TEST_F( utObjImportExport, obj_import_test ) {
|
|||
differ.showReport();
|
||||
|
||||
m_im->FreeScene();
|
||||
for(unsigned int i = 0; i < expected->mNumMeshes; ++i)
|
||||
{
|
||||
delete expected->mMeshes[i];
|
||||
}
|
||||
delete[] expected->mMeshes;
|
||||
expected->mMeshes = nullptr;
|
||||
delete[] expected->mMaterials;
|
||||
expected->mMaterials = nullptr;
|
||||
delete expected;
|
||||
}
|
||||
|
||||
TEST_F( utObjImportExport, issue1111_no_mat_name_Test ) {
|
||||
|
|
|
@ -72,4 +72,5 @@ TEST_F( utRevmoveVCProcess, issue1266_ProcessMeshTest_NoCrash ) {
|
|||
scene->mMeshes[ 0 ] = mesh;
|
||||
RemoveVCProcess *process = new RemoveVCProcess;
|
||||
process->Execute( scene );
|
||||
}
|
||||
delete scene;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "UnitTestPCH.h"
|
||||
#include <assimp/SceneCombiner.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace ::Assimp;
|
||||
|
||||
|
@ -63,8 +64,10 @@ TEST_F( utSceneCombiner, MergeMeshes_ValidNames_Test ) {
|
|||
mesh3->mName.Set( "mesh_3" );
|
||||
merge_list.push_back( mesh3 );
|
||||
|
||||
aiMesh *out( nullptr );
|
||||
SceneCombiner::MergeMeshes( &out, 0, merge_list.begin(), merge_list.end() );
|
||||
std::unique_ptr<aiMesh> out;
|
||||
aiMesh* ptr = nullptr;
|
||||
SceneCombiner::MergeMeshes( &ptr, 0, merge_list.begin(), merge_list.end() );
|
||||
out.reset(ptr);
|
||||
std::string outName = out->mName.C_Str();
|
||||
EXPECT_EQ( "mesh_1.mesh_2.mesh_3", outName );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue