Store allocated temporaries in a variable so they can be freed

If a function that returns an allocated pointer is passed directly into
something that does not take ownership of the pointer, the allocation is
leaked.  This can be fixed by assigning the pointer to a new variable
and freeing it after operation on the memory.
This commit is contained in:
Maarten Bosmans
2023-03-17 21:39:26 +01:00
committed by John Ralls
parent 0d86be6d2a
commit 6be682b645
5 changed files with 51 additions and 35 deletions

View File

@@ -99,9 +99,11 @@ GncSqlColumnTableEntry::add_objectref_guid_to_query (QofIdTypeConst obj_name,
auto inst = get_row_value_from_object<QofInstance*>(obj_name, pObject);
if (inst == nullptr) return;
auto guid = qof_instance_get_guid (inst);
if (guid != nullptr)
vec.emplace_back (std::make_pair (std::string{m_col_name},
quote_string(guid_to_string(guid))));
if (guid != nullptr) {
gchar *guid_s = guid_to_string(guid);
vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
g_free(guid_s);
}
}
void
@@ -356,9 +358,9 @@ GncSqlColumnTableEntryImpl<CT_GUID>::add_to_query(QofIdTypeConst obj_name,
if (s != nullptr)
{
vec.emplace_back (std::make_pair (std::string{m_col_name},
quote_string(guid_to_string(s))));
gchar *guid_s = guid_to_string(s);
vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
g_free(guid_s);
return;
}
}