瀏覽代碼

CSM: Fix a possible memory leak by using std::unique_ptr

Turo Lamminen 7 年之前
父節點
當前提交
5278e1a5f8
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      code/CSMLoader.cpp

+ 2 - 2
code/CSMLoader.cpp

@@ -136,7 +136,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
     TextFileToBuffer(file.get(),mBuffer2);
     TextFileToBuffer(file.get(),mBuffer2);
     const char* buffer = &mBuffer2[0];
     const char* buffer = &mBuffer2[0];
 
 
-    aiAnimation* anim = new aiAnimation();
+    std::unique_ptr<aiAnimation> anim(new aiAnimation());
     int first = 0, last = 0x00ffffff;
     int first = 0, last = 0x00ffffff;
 
 
     // now process the file and look out for '$' sections
     // now process the file and look out for '$' sections
@@ -294,8 +294,8 @@ void CSMImporter::InternReadFile( const std::string& pFile,
 
 
     // Store the one and only animation in the scene
     // Store the one and only animation in the scene
     pScene->mAnimations    = new aiAnimation*[pScene->mNumAnimations=1];
     pScene->mAnimations    = new aiAnimation*[pScene->mNumAnimations=1];
-    pScene->mAnimations[0] = anim;
     anim->mName.Set("$CSM_MasterAnim");
     anim->mName.Set("$CSM_MasterAnim");
+    pScene->mAnimations[0] = anim.release();
 
 
     // mark the scene as incomplete and run SkeletonMeshBuilder on it
     // mark the scene as incomplete and run SkeletonMeshBuilder on it
     pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
     pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;