Don't return pointer to dead object.

This commit is contained in:
Hermann Kraus 2012-03-09 13:26:11 +01:00
parent cd8cfc6527
commit b71460d4dd
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -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