From f9da0646866647c110c54d49d01f016fdef110fb Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Thu, 16 Aug 2018 11:40:03 +0200
Subject: [PATCH] [GL/IO/Qt] Catch exceptions while reading gml file.

---
 GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp | 34 ++++++++++++++++++++------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
index ae85edd9d71..0bbcd9ce59c 100644
--- a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
+++ b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
@@ -113,10 +113,19 @@ int XmlGmlInterface::readFile(const QString &fileName)
         }
         else if (nodeName.compare("polylines") == 0)
         {
-            readPolylines(
-                type_node, polylines.get(), *_geo_objs.getPointVec(gliName),
-                _geo_objs.getPointVecObj(gliName)->getIDMap(), ply_names.get());
-
+            try
+            {
+                readPolylines(type_node, polylines.get(),
+                              *_geo_objs.getPointVec(gliName),
+                              _geo_objs.getPointVecObj(gliName)->getIDMap(),
+                              ply_names.get());
+            }
+            catch (std::runtime_error const& err)
+            {
+                // further reading is aborted and it is necessary to clean up
+                _geo_objs.removePointVec(gliName);
+                throw;
+            }
             // if names-map is empty, set it to nullptr because it is not needed
             if (ply_names->empty())
             {
@@ -125,9 +134,20 @@ int XmlGmlInterface::readFile(const QString &fileName)
         }
         else if (nodeName.compare("surfaces") == 0)
         {
-            readSurfaces(
-                type_node, surfaces.get(), *_geo_objs.getPointVec(gliName),
-                _geo_objs.getPointVecObj(gliName)->getIDMap(), sfc_names.get());
+            try
+            {
+                readSurfaces(type_node, surfaces.get(),
+                             *_geo_objs.getPointVec(gliName),
+                             _geo_objs.getPointVecObj(gliName)->getIDMap(),
+                             sfc_names.get());
+            }
+            catch (std::runtime_error const& err)
+            {
+                // further reading is aborted and it is necessary to clean up
+                _geo_objs.removePointVec(gliName);
+                _geo_objs.removePolylineVec(gliName);
+                throw;
+            }
 
             // if names-map is empty, set it to nullptr because it is not needed
             if (sfc_names->empty())
-- 
GitLab