diff --git a/libgnucash/backend/xml/test/test-kvp-frames.cpp b/libgnucash/backend/xml/test/test-kvp-frames.cpp index 1b8e39fcce..81ab41b759 100644 --- a/libgnucash/backend/xml/test/test-kvp-frames.cpp +++ b/libgnucash/backend/xml/test/test-kvp-frames.cpp @@ -35,7 +35,7 @@ test_kvp_get_slot (int run, { gchar* tmp; failure_args (msg, __FILE__, __LINE__, "run=%d", run); - printf (" Value is %s\n", test_val2->to_string ()); + printf (" Value is %s\n", test_val2->to_string ().c_str ()); } } diff --git a/libgnucash/engine/kvp-value.cpp b/libgnucash/engine/kvp-value.cpp index 277cca034c..55e0e6e08f 100644 --- a/libgnucash/engine/kvp-value.cpp +++ b/libgnucash/engine/kvp-value.cpp @@ -149,16 +149,8 @@ struct to_string_visitor : boost::static_visitor /*Since val is passed by value, we can modify it*/ for (;val; val = val->next) { - gchar *tmp3; auto realvalue = static_cast(val->data); - tmp3 = realvalue->to_string(); - output << ' '; - if (tmp3) - { - output << tmp3; - g_free(tmp3); - } - output << ','; + output << ' ' << realvalue->to_string() << ','; } output << " ]"; @@ -207,7 +199,7 @@ struct to_string_visitor : boost::static_visitor } }; -char * +std::string KvpValueImpl::to_string() const noexcept { std::ostringstream ret; @@ -215,7 +207,7 @@ KvpValueImpl::to_string() const noexcept boost::apply_visitor(visitor, datastore); /*We still use g_strdup since the return value will be freed by g_free*/ - return g_strdup(ret.str().c_str()); + return ret.str(); } static int diff --git a/libgnucash/engine/kvp-value.hpp b/libgnucash/engine/kvp-value.hpp index 99ddcf8095..1aeb1fd89a 100644 --- a/libgnucash/engine/kvp-value.hpp +++ b/libgnucash/engine/kvp-value.hpp @@ -137,7 +137,7 @@ struct KvpValueImpl KvpValueImpl::Type get_type() const noexcept; - char * to_string() const noexcept; + std::string to_string() const noexcept; template T get() const noexcept;