From 83f08b413224c78c186c44350e761fc8fad622dc Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 25 Sep 2012 14:29:33 +0200
Subject: [PATCH] changed creating Edge objects

---
 FileIO/Legacy/MeshIO.cpp        |  9 +++++++--
 FileIO/MeshIO/GMSHInterface.cpp |  9 +++++++--
 FileIO/XmlIO/VTKInterface.cpp   | 16 ++++++++++------
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/FileIO/Legacy/MeshIO.cpp b/FileIO/Legacy/MeshIO.cpp
index 31068bc4629..22c49882d83 100644
--- a/FileIO/Legacy/MeshIO.cpp
+++ b/FileIO/Legacy/MeshIO.cpp
@@ -133,11 +133,16 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector
 
 	switch(elem_type)
 	{
-	case MshElemType::EDGE:
+	case MshElemType::EDGE: {
 		for (int i = 0; i < 2; i++)
 			ss >> idx[i];
-		elem = new MeshLib::Edge(nodes[idx[1]], nodes[idx[0]], patch_index);
+		// edge_nodes array will be deleted from Edge object
+		MeshLib::Node** edge_nodes(new MeshLib::Node*[2]);
+		edge_nodes[0] = nodes[idx[1]];
+		edge_nodes[1] = nodes[idx[0]];
+		elem = new MeshLib::Edge(edge_nodes, patch_index);
 		break;
+	}
 	case MshElemType::TRIANGLE:
 		for (int i = 0; i < 3; i++)
 			ss >> idx[i];
diff --git a/FileIO/MeshIO/GMSHInterface.cpp b/FileIO/MeshIO/GMSHInterface.cpp
index 32ff2a5e8a3..d63bcd842bd 100644
--- a/FileIO/MeshIO/GMSHInterface.cpp
+++ b/FileIO/MeshIO/GMSHInterface.cpp
@@ -136,10 +136,15 @@ MeshLib::Mesh* GMSHInterface::readGMSHMesh(std::string const& fname)
 
 				switch (type)
 				{
-					case 1:
+					case 1: {
 						readNodeIDs(in, 2, node_ids, id_map);
-						elem = new MeshLib::Edge(nodes[node_ids[0]], nodes[node_ids[1]], 0);
+						// edge_nodes array will be deleted from Edge object
+						MeshLib::Node** edge_nodes(new MeshLib::Node*[2]);
+						edge_nodes[0] = nodes[node_ids[0]];
+						edge_nodes[1] = nodes[node_ids[1]];
+						elem = new MeshLib::Edge(edge_nodes, 0);
 						break;
+					}
 					case 2:
 						readNodeIDs(in, 3, node_ids, id_map);
 						elem = new MeshLib::Tri(nodes[node_ids[2]], nodes[node_ids[1]], nodes[node_ids[0]], mat_id);
diff --git a/FileIO/XmlIO/VTKInterface.cpp b/FileIO/XmlIO/VTKInterface.cpp
index 5a02297e5b7..a9db98cc6b3 100644
--- a/FileIO/XmlIO/VTKInterface.cpp
+++ b/FileIO/XmlIO/VTKInterface.cpp
@@ -32,7 +32,7 @@
 namespace FileIO {
 
 using namespace rapidxml;
-	
+
 VTKInterface::VTKInterface()
 : _export_name(""), _mesh(NULL), _doc(new xml_document<>), _use_compressor(false)
 {
@@ -96,7 +96,7 @@ MeshLib::Mesh* VTKInterface::readVTUFile(const std::string &file_name)
 			std::vector<unsigned> cell_types(nElems);
 
 			const rapidxml::xml_node<>* mat_id_node (piece_node->first_node("CellData")->first_node("DataArray"));
-			if (mat_id_node && 
+			if (mat_id_node &&
 				((std::string(mat_id_node->first_attribute("Name")->value()).compare("MaterialIDs") == 0) ||
 				 (std::string(mat_id_node->first_attribute("Name")->value()).compare("MatGroup") == 0)))
 			{
@@ -112,9 +112,9 @@ MeshLib::Mesh* VTKInterface::readVTUFile(const std::string &file_name)
 
 
 			const rapidxml::xml_node<>* points_node (piece_node->first_node("Points")->first_node("DataArray"));
-			// This _may_ have an attribute "Name" with the value "Points" but you cannot count on it. 
+			// This _may_ have an attribute "Name" with the value "Points" but you cannot count on it.
 			// However, there shouldn't be any other DataArray nodes so most likely not checking the name isn't a problem.
-			if (points_node) 
+			if (points_node)
 			{
 				if (std::string(points_node->first_attribute("format")->value()).compare("ascii") == 0)
 				{
@@ -185,10 +185,14 @@ MeshLib::Element* VTKInterface::readElement(std::stringstream &iss, const std::v
 	unsigned node_ids[8];
 	switch (type)
 	{
-	case 3: //line
+	case 3: { //line
 		for (unsigned i(0); i<2; i++) iss >> node_ids[i];
-		return new MeshLib::Edge(nodes[node_ids[0]], nodes[node_ids[1]], material);
+		MeshLib::Node** edge_nodes(new MeshLib::Node*[2]);
+		edge_nodes[0] = nodes[node_ids[0]];
+		edge_nodes[1] = nodes[node_ids[1]];
+		return new MeshLib::Edge(edge_nodes, material);
 		break;
+	}
 	case 5: //triangle
 		for (unsigned i(0); i<3; i++) iss >> node_ids[i];
 		return new MeshLib::Tri(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], material);
-- 
GitLab