diff --git a/include/mapnik/config_error.hpp b/include/mapnik/config_error.hpp index 00ec3be8a..1b1e8fefa 100644 --- a/include/mapnik/config_error.hpp +++ b/include/mapnik/config_error.hpp @@ -47,7 +47,9 @@ protected: mutable unsigned line_number_; mutable std::string file_; mutable std::string node_name_; + mutable std::string msg_; }; + } #endif // MAPNIK_CONFIG_ERROR_HPP diff --git a/src/config_error.cpp b/src/config_error.cpp index 6837f3cbd..2adc487fb 100644 --- a/src/config_error.cpp +++ b/src/config_error.cpp @@ -4,7 +4,7 @@ namespace mapnik { config_error::config_error(std::string const& what, xml_node const* node, std::string const& filename) - : what_( what ), file_(filename) + : what_( what ), line_number_(0), file_(filename), node_name_(), msg_() { if (node) { @@ -15,7 +15,7 @@ config_error::config_error(std::string const& what, xml_node const* node, std::s config_error::config_error(unsigned line_number, std::string const& filename, std::string const& what) - : what_( what ), line_number_(line_number), file_(filename) + : what_( what ), line_number_(line_number), file_(filename), node_name_(), msg_() { } @@ -28,7 +28,8 @@ config_error::config_error(unsigned line_number, std::string const& filename, st if (!node_name_.empty()) s << " in node "<< node_name_; if (line_number_ > 0 || !file_.empty()) s << ": "; s << what_; - return s.str().c_str(); + msg_ = s.str(); //Avoid returning pointer to dead object + return msg_.c_str(); } void config_error::append_context(const std::string & ctx, xml_node const* node, std::string const& filename) const