@@ -239,6 +239,23 @@ static vector<Parseable*> parse_pois(rapidxml::xml_node<>* root_node, map<string
239
239
return markers;
240
240
}
241
241
242
+ class XMLFileData {
243
+ public:
244
+ unique_ptr<basic_istream<char >> raw_file;
245
+ rapidxml::file<char >* xml_file;
246
+ string display_path;
247
+ rapidxml::xml_document<char > xml_document;
248
+
249
+ XMLFileData (unique_ptr<basic_istream<char >> input, const MarkerPackFile& filepath) {
250
+ this ->raw_file = std::move (input);
251
+ this ->xml_file = new rapidxml::file<char >(*this ->raw_file );
252
+ this ->display_path = filepath.tmp_get_path ();
253
+ this ->xml_document .parse <rapidxml::parse_non_destructive | rapidxml::parse_no_data_nodes>(this ->xml_file ->data (), this ->display_path .c_str ());
254
+ }
255
+ };
256
+
257
+ vector<XMLFileData*> xml_files_to_cleanup;
258
+
242
259
// //////////////////////////////////////////////////////////////////////////////
243
260
// parse_xml_file
244
261
//
@@ -251,16 +268,10 @@ set<string> parse_xml_file(
251
268
) {
252
269
vector<XMLError*> errors;
253
270
254
- unique_ptr<basic_istream<char >> infile = open_file_for_read (xml_filepath);
255
-
256
- rapidxml::file<> xml_file (*infile);
257
-
258
- string tmp_get_path = xml_filepath.tmp_get_path ();
271
+ XMLFileData* xml_file_data = new XMLFileData (open_file_for_read (xml_filepath), xml_filepath); // This is a memory leak
272
+ xml_files_to_cleanup.push_back (xml_file_data);
259
273
260
- rapidxml::xml_document<> doc;
261
- doc.parse <rapidxml::parse_non_destructive | rapidxml::parse_no_data_nodes>(xml_file.data (), tmp_get_path.c_str ());
262
-
263
- rapidxml::xml_node<>* root_node = doc.first_node ();
274
+ rapidxml::xml_node<>* root_node = xml_file_data->xml_document .first_node ();
264
275
// Validate the Root Node
265
276
if (get_node_name (root_node) != " OverlayData" ) {
266
277
errors.push_back (new XMLNodeNameError (" Root node should be of type OverlayData" , root_node));
@@ -295,6 +306,13 @@ set<string> parse_xml_file(
295
306
return category_names;
296
307
}
297
308
309
+ void cleanup_xml_files () {
310
+ for (size_t i = 0 ; i < xml_files_to_cleanup.size (); i++) {
311
+ delete xml_files_to_cleanup[i]->xml_file ;
312
+ delete xml_files_to_cleanup[i];
313
+ }
314
+ }
315
+
298
316
// //////////////////////////////////////////////////////////////////////////////
299
317
// //////////////////////////////// SERIALIZE ///////////////////////////////////
300
318
// //////////////////////////////////////////////////////////////////////////////
0 commit comments