Fix memory leak in char* type KvpValue and fix improper uses

The core issue was that the delete visitor was never called because its parameter
type (char *) didn't match the boost::variant type (const char *).
Fixing the visitor's parameter type also require a const_cast
back to char * because that's what g_free takes as argument.

The rest of this commit is merely fixing KvpValue instantiations that
tried to create a char* KvpValue from a stack based const string instead
of a heap allocated one. That would bomb out on calling the
delete visitor.
This commit is contained in:
Geert Janssens
2018-09-10 19:49:43 +02:00
parent b866d7d955
commit 48b29f5e91
9 changed files with 17 additions and 17 deletions

View File

@@ -139,7 +139,7 @@ setup_memory (Fixture* fixture, gconstpointer pData)
frame->set ({"double-val"}, new KvpValue (3.14159));
frame->set ({"numeric-val"}, new KvpValue (gnc_numeric_zero ()));
frame->set ({"time-val"}, new KvpValue (gnc_time(nullptr)));
frame->set ({"string-val"}, new KvpValue ("abcdefghijklmnop"));
frame->set ({"string-val"}, new KvpValue (g_strdup ("abcdefghijklmnop")));
auto guid = qof_instance_get_guid (QOF_INSTANCE (acct1));
frame->set ({"guid-val"}, new KvpValue (const_cast<GncGUID*> (guid_copy (
guid))));

View File

@@ -205,7 +205,7 @@ dom_tree_to_numeric_kvp_value (xmlNodePtr node)
static KvpValue*
dom_tree_to_string_kvp_value (xmlNodePtr node)
{
gchar* datext;
const gchar* datext;
KvpValue* ret = NULL;
datext = dom_tree_to_text (node);