diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-09-11 12:12:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-09-11 12:12:54 +0300 |
commit | bb20c96da562a294f3f606ca6db446389d6765cb (patch) | |
tree | 58aaf909bc8d9af492f8c59a6298aa6f02e3a516 /source/blender/collada | |
parent | 42825dc1fc03609efed30259fa69cc31819be31c (diff) |
Fix memory leaks in collada import
Diffstat (limited to 'source/blender/collada')
-rw-r--r-- | source/blender/collada/AnimationImporter.cpp | 6 | ||||
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 36 |
2 files changed, 30 insertions, 12 deletions
diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index dbff917d2c1..1bcf51f9d1f 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -898,8 +898,6 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, std::multimap<COLLADAFW::UniqueId, Object *>& object_map, std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map) { - AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map); - bool is_joint = node->getType() == COLLADAFW::Node::JOINT; COLLADAFW::UniqueId uid = node->getUniqueId(); COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid]; @@ -915,6 +913,8 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, return; } + + AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map); bAction *act; if ( (animType->transform) != 0) { @@ -1116,6 +1116,8 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, } } } + + delete animType; } void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector<FCurve *>& animcurves, COLLADAFW::Node *root, COLLADAFW::Node *node, COLLADAFW::Transformation *tm) diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 0aff5147060..674a79f0fe7 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -136,11 +136,14 @@ bool DocumentImporter::import() const std::string encodedFilename = bc_url_encode(mFilename); if (!root.loadDocument(encodedFilename)) { fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n"); + delete ehandler; return false; } - if (errorHandler.hasError()) + if (errorHandler.hasError()) { + delete ehandler; return false; + } /** TODO set up scene graph and such here */ @@ -151,10 +154,10 @@ bool DocumentImporter::import() if (!root2.loadDocument(encodedFilename)) { fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n"); + delete ehandler; return false; } - - + delete ehandler; return true; @@ -223,6 +226,7 @@ void DocumentImporter::finish() for (unsigned int i = 0; i < roots.getCount(); i++) { std::vector<Object *> *objects_done = write_node(roots[i], NULL, sce, NULL, false); objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end()); + delete objects_done; } // update scene @@ -275,6 +279,8 @@ void DocumentImporter::finish() } bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); + + delete objects_to_scale; } @@ -499,6 +505,9 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA std::string id = node->getOriginalId(); std::string name = node->getName(); + // if node has child nodes write them + COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes(); + std::vector<Object *> *objects_done = new std::vector<Object *>(); std::vector<Object *> *root_objects = new std::vector<Object *>(); @@ -524,7 +533,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA if (parent_node == NULL) { // for skeletons without root node all has been done above. // Skeletons with root node are handled further down. - return root_objects; + goto finally; } } else { @@ -638,7 +647,9 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA // XXX: if there're multiple instances, only one is stored - if (!ob) return root_objects; + if (!ob) { + goto finally; + } for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) { ob = *it; @@ -673,9 +684,6 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA } } - // if node has child nodes write them - COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes(); - if (objects_done->size() > 0) { ob = *objects_done->begin(); } @@ -684,9 +692,15 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA } for (unsigned int i = 0; i < child_nodes.getCount(); i++) { - write_node(child_nodes[i], node, sce, ob, is_library_node); + std::vector<Object *> *child_objects; + child_objects = write_node(child_nodes[i], node, sce, ob, is_library_node); + delete child_objects; } + +finally: + delete objects_done; + return root_objects; } @@ -725,7 +739,9 @@ bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryN const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes(); for (unsigned int i = 0; i < nodes.getCount(); i++) { - write_node(nodes[i], NULL, sce, NULL, true); + std::vector<Object *> *child_objects; + child_objects = write_node(nodes[i], NULL, sce, NULL, true); + delete child_objects; } return true; |