Browse Source

Fix coverity findings.

Kim Kulling 8 years ago
parent
commit
ba2f377b52
4 changed files with 25 additions and 6 deletions
  1. 1 0
      code/ObjFileParser.cpp
  2. 8 2
      code/X3DImporter.cpp
  3. 15 3
      code/glTFExporter.cpp
  4. 1 1
      include/assimp/types.h

+ 1 - 0
code/ObjFileParser.cpp

@@ -451,6 +451,7 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
         DefaultLogger::get()->error("Obj: Ignoring empty face");
         // skip line and clean up
         m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
+        delete face;
         return;
     }
 

+ 8 - 2
code/X3DImporter.cpp

@@ -1480,10 +1480,11 @@ void X3DImporter::ParseNode_Head()
 				XML_CheckNode_MustBeEmpty();
 
 				// adding metadata from <head> as MetaString from <Scene>
-				CX3DImporter_NodeElement_MetaString* ms = new CX3DImporter_NodeElement_MetaString(NodeElement_Cur);
+                bool added( false );
+                CX3DImporter_NodeElement_MetaString* ms = new CX3DImporter_NodeElement_MetaString(NodeElement_Cur);
 
 				ms->Name = mReader->getAttributeValueSafe("name");
-				// name can not be empty
+				// name must not be empty
 				if(!ms->Name.empty())
 				{
 					ms->Value.push_back(mReader->getAttributeValueSafe("content"));
@@ -1491,8 +1492,13 @@ void X3DImporter::ParseNode_Head()
                     if ( NodeElement_Cur != nullptr )
                     {
                         NodeElement_Cur->Child.push_back( ms );
+                        added = true;
                     }
 				}
+                // if an error has occurred, release instance
+                if ( !added ) {
+                    delete ms;
+                }
 			}// if(XML_CheckNode_NameEqual("meta"))
 		}// if(mReader->getNodeType() == irr::io::EXN_ELEMENT)
 		else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END)

+ 15 - 3
code/glTFExporter.cpp

@@ -488,6 +488,9 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buf
     if ( vertexWeightAccessor ) {
         p.attributes.weight.push_back( vertexWeightAccessor );
     }
+    delete[] jointsPerVertex;
+    delete[] vertexWeightData;
+    delete[] vertexJointData;
 }
 
 void glTFExporter::ExportMeshes()
@@ -867,7 +870,10 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
         }
 
         Ref<Accessor> tranAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, translationData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
-        if (tranAccessor) animRef->Parameters.translation = tranAccessor;
+        if ( tranAccessor ) {
+            animRef->Parameters.translation = tranAccessor;
+        }
+        delete[] translationData;
     }
 
     //-------------------------------------------------------
@@ -879,7 +885,10 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
         }
 
         Ref<Accessor> scaleAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumScalingKeys, scaleData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
-        if (scaleAccessor) animRef->Parameters.scale = scaleAccessor;
+        if ( scaleAccessor ) {
+            animRef->Parameters.scale = scaleAccessor;
+        }
+        delete[] scaleData;
     }
 
     //-------------------------------------------------------
@@ -894,7 +903,10 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
         }
 
         Ref<Accessor> rotAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumRotationKeys, rotationData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);
-        if (rotAccessor) animRef->Parameters.rotation = rotAccessor;
+        if ( rotAccessor ) {
+            animRef->Parameters.rotation = rotAccessor;
+        }
+        delete[] rotationData;
     }
 }
 

+ 1 - 1
include/assimp/types.h

@@ -109,7 +109,7 @@ extern "C" {
 
 /** Maximum dimension for strings, ASSIMP strings are zero terminated. */
 #ifdef __cplusplus
-const size_t MAXLEN = 1024;
+static const size_t MAXLEN = 1024;
 #else
 #   define MAXLEN 1024
 #endif