From: Martin Quinson Date: Tue, 19 Nov 2019 00:33:19 +0000 (+0100) Subject: plug a memleak on parse error :) X-Git-Tag: v3.25~380 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3900b29f1b0eba8ddc4cbc477dfade991386a7ca plug a memleak on parse error :) The most important fix ever! --- diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 7f3918f085..ad3498abfe 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -162,17 +162,17 @@ class XBT_PUBLIC ParseError : public Exception, public std::invalid_argument { int line_; std::string file_; std::string msg_; + char* rendered_what = nullptr; public: ParseError(int line, std::string& file, std::string&& msg) : Exception(XBT_THROW_POINT, std::move(msg)), std::invalid_argument(msg), line_(line), file_(file), msg_(msg) { + rendered_what = bprintf("Parse error at %s:%d: %s", file_.c_str(), line_, msg_.c_str()); } + ~ParseError() { free(rendered_what); } - const char* what() const noexcept override - { - return bprintf("Parse error at %s:%d: %s", file_.c_str(), line_, msg_.c_str()); - } + const char* what() const noexcept override { return rendered_what; } }; class XBT_PUBLIC ForcefulKillException {