mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
committed by
John Ralls
parent
0d86be6d2a
commit
6be682b645
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user