FBX: fix memory leak. Connection objects in Document never freed. See #307

pull/321/head
Alexander Gessler 2014-07-13 14:07:19 +02:00
parent cd88ea745d
commit 5ae010028b
1 changed files with 10 additions and 5 deletions

View File

@ -253,8 +253,8 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
: settings(settings) : settings(settings)
, parser(parser) , parser(parser)
{ {
// cannot use array default initialization syntax because vc8 fails on it // Cannot use array default initialization syntax because vc8 fails on it
for (unsigned int i = 0; i < 7; ++i) { for (unsigned int i = 0; i < sizeof(creationTimeStamp) / sizeof(creationTimeStamp[0]); ++i) {
creationTimeStamp[i] = 0; creationTimeStamp[i] = 0;
} }
@ -263,7 +263,7 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
ReadGlobalSettings(); ReadGlobalSettings();
// this order is important, connections need parsed objects to check // This order is important, connections need parsed objects to check
// whether connections are ok or not. Objects may not be evaluated yet, // whether connections are ok or not. Objects may not be evaluated yet,
// though, since this may require valid connections. // though, since this may require valid connections.
ReadObjects(); ReadObjects();
@ -277,13 +277,18 @@ Document::~Document()
BOOST_FOREACH(ObjectMap::value_type& v, objects) { BOOST_FOREACH(ObjectMap::value_type& v, objects) {
delete v.second; delete v.second;
} }
BOOST_FOREACH(ConnectionMap::value_type& v, src_connections) {
delete v.second;
}
// |dest_connections| contain the same Connection objects as the |src_connections|
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Document::ReadHeader() void Document::ReadHeader()
{ {
// read ID objects from "Objects" section // Read ID objects from "Objects" section
const Scope& sc = parser.GetRootScope(); const Scope& sc = parser.GetRootScope();
const Element* const ehead = sc["FBXHeaderExtension"]; const Element* const ehead = sc["FBXHeaderExtension"];
if(!ehead || !ehead->Compound()) { if(!ehead || !ehead->Compound()) {
@ -293,7 +298,7 @@ void Document::ReadHeader()
const Scope& shead = *ehead->Compound(); const Scope& shead = *ehead->Compound();
fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0)); fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
// while we maye have some success with newer files, we don't support // While we maye have some success with newer files, we don't support
// the older 6.n fbx format // the older 6.n fbx format
if(fbxVersion < 7100) { if(fbxVersion < 7100) {
DOMError("unsupported, old format version, supported are only FBX 2011, FBX 2012 and FBX 2013"); DOMError("unsupported, old format version, supported are only FBX 2011, FBX 2012 and FBX 2013");