From: Arnaud Giersch Date: Mon, 23 Nov 2020 15:15:20 +0000 (+0100) Subject: Use std::unique_ptr with std::ifstream. X-Git-Tag: v3.26~131 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f67dd7cce4ccc1f6c3cb81de389cdc755ba451a4 Use std::unique_ptr with std::ifstream. --- diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index 9a85416023..03b6da096f 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -211,12 +212,11 @@ Profile* Profile::from_file(const std::string& path) xbt_assert(not path.empty(), "Cannot parse a trace from an empty filename"); xbt_assert(trace_list.find(path) == trace_list.end(), "Refusing to define trace %s twice", path.c_str()); - const std::ifstream* f = surf_ifsopen(path); + auto f = std::unique_ptr(surf_ifsopen(path)); xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", path.c_str(), (boost::join(surf_path, ":")).c_str()); std::stringstream buffer; buffer << f->rdbuf(); - delete f; return Profile::from_string(path, buffer.str(), -1); } diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 25c6cafd96..7308985348 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -511,7 +511,7 @@ std::map* FileSystemDiskExt::parse_content(const std::st auto* parse_content = new std::map(); - std::ifstream* fs = surf_ifsopen(filename); + auto fs = std::unique_ptr(surf_ifsopen(filename)); xbt_assert(not fs->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(), (boost::join(surf_path, ":")).c_str()); @@ -529,7 +529,6 @@ std::map* FileSystemDiskExt::parse_content(const std::st parse_content->insert({tokens.front(), size}); } } while (not fs->eof()); - delete fs; return parse_content; } @@ -540,7 +539,7 @@ std::map* FileSystemStorageExt::parse_content(const std: auto* parse_content = new std::map(); - std::ifstream* fs = surf_ifsopen(filename); + auto fs = std::unique_ptr(surf_ifsopen(filename)); xbt_assert(not fs->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(), (boost::join(surf_path, ":")).c_str()); @@ -558,7 +557,6 @@ std::map* FileSystemStorageExt::parse_content(const std: parse_content->insert({tokens.front(), size}); } } while (not fs->eof()); - delete fs; return parse_content; }