[gnc-commodity.h] callers must free g_list

callers to gnc_commodity_namespace_get_commodity_list and
gnc_commodity_table_get_namespaces_list must free the GList.
pull/1530/merge
Christopher Lam 2 years ago
parent 0fc6e4f7df
commit a99491d034

@ -422,6 +422,7 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
list = gnc_commodity_table_get_namespaces_list(ct); list = gnc_commodity_table_get_namespaces_list(ct);
i = gtk_tree_path_get_indices (path)[0]; i = gtk_tree_path_get_indices (path)[0];
name_space = g_list_nth_data (list, i); name_space = g_list_nth_data (list, i);
g_list_free (list);
if (!name_space) if (!name_space)
{ {
LEAVE("invalid path at namespace"); LEAVE("invalid path at namespace");
@ -443,6 +444,7 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
i = gtk_tree_path_get_indices (path)[1]; i = gtk_tree_path_get_indices (path)[1];
commodity = g_list_nth_data (list, i); commodity = g_list_nth_data (list, i);
g_list_free (list);
if (!commodity) if (!commodity)
{ {
LEAVE("invalid path at commodity"); LEAVE("invalid path at commodity");
@ -503,6 +505,7 @@ gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
gtk_tree_path_append_index (path, g_list_index (ns_list, name_space)); gtk_tree_path_append_index (path, g_list_index (ns_list, name_space));
gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3)); gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
debug_path(LEAVE, path); debug_path(LEAVE, path);
g_list_free (ns_list);
return path; return path;
} }
@ -671,6 +674,7 @@ gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
n = GPOINTER_TO_INT(iter->user_data3) + 1; n = GPOINTER_TO_INT(iter->user_data3) + 1;
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
g_list_free (list);
if (iter->user_data2 == NULL) if (iter->user_data2 == NULL)
{ {
LEAVE("no next iter"); LEAVE("no next iter");
@ -713,6 +717,7 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, 0); iter->user_data2 = g_list_nth_data(list, 0);
iter->user_data3 = GINT_TO_POINTER(0); iter->user_data3 = GINT_TO_POINTER(0);
LEAVE("ns iter %p (%s)", iter, iter_to_string(iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -731,6 +736,7 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, 0); iter->user_data2 = g_list_nth_data(list, 0);
iter->user_data3 = GINT_TO_POINTER(0); iter->user_data3 = GINT_TO_POINTER(0);
LEAVE("cm iter %p (%s)", iter, iter_to_string(iter)); LEAVE("cm iter %p (%s)", iter, iter_to_string(iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -758,7 +764,9 @@ gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
name_space = (gnc_commodity_namespace *)iter->user_data2; name_space = (gnc_commodity_namespace *)iter->user_data2;
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
LEAVE("%s children", list ? "has" : "no"); LEAVE("%s children", list ? "has" : "no");
return list != NULL; gboolean rv = (list != NULL);
g_list_free (list);
return rv;
} }
static int static int
@ -780,7 +788,9 @@ gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
ct = model->commodity_table; ct = model->commodity_table;
list = gnc_commodity_table_get_namespaces_list(ct); list = gnc_commodity_table_get_namespaces_list(ct);
LEAVE("ns list length %d", g_list_length(list)); LEAVE("ns list length %d", g_list_length(list));
return g_list_length (list); guint rv = g_list_length (list);
g_list_free (list);
return rv;
} }
if (iter->user_data == ITER_IS_NAMESPACE) if (iter->user_data == ITER_IS_NAMESPACE)
@ -788,7 +798,9 @@ gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
name_space = (gnc_commodity_namespace *)iter->user_data2; name_space = (gnc_commodity_namespace *)iter->user_data2;
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
LEAVE("cm list length %d", g_list_length(list)); LEAVE("cm list length %d", g_list_length(list));
return g_list_length (list); guint rv = g_list_length (list);
g_list_free (list);
return rv;
} }
LEAVE("0"); LEAVE("0");
@ -823,6 +835,7 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
iter->user_data3 = GINT_TO_POINTER(n); iter->user_data3 = GINT_TO_POINTER(n);
LEAVE("ns iter %p (%s)", iter, iter_to_string(iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(iter));
g_list_free (list);
return iter->user_data2 != NULL; return iter->user_data2 != NULL;
} }
@ -836,6 +849,7 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
iter->user_data3 = GINT_TO_POINTER(n); iter->user_data3 = GINT_TO_POINTER(n);
LEAVE("cm iter %p (%s)", iter, iter_to_string(iter)); LEAVE("cm iter %p (%s)", iter, iter_to_string(iter));
g_list_free (list);
return iter->user_data2 != NULL; return iter->user_data2 != NULL;
} }
@ -877,6 +891,7 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
iter->user_data2 = name_space; iter->user_data2 = name_space;
iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space)); iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space));
LEAVE("ns iter %p (%s)", iter, iter_to_string(iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -919,6 +934,7 @@ gnc_tree_model_commodity_get_iter_from_commodity (GncTreeModelCommodity *model,
} }
n = g_list_index(list, commodity); n = g_list_index(list, commodity);
g_list_free (list);
if (n == -1) if (n == -1)
{ {
LEAVE("not in list"); LEAVE("not in list");
@ -996,6 +1012,7 @@ gnc_tree_model_commodity_get_iter_from_namespace (GncTreeModelCommodity *model,
} }
n = g_list_index(list, name_space); n = g_list_index(list, name_space);
g_list_free (list);
if (n == -1) if (n == -1)
{ {
LEAVE(""); LEAVE("");

@ -491,6 +491,7 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
LEAVE("invalid path at namespace"); LEAVE("invalid path at namespace");
return FALSE; return FALSE;
} }
g_list_free (ns_list);
if (depth == 1) if (depth == 1)
{ {
@ -507,6 +508,7 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
cm_list = gnc_commodity_namespace_get_commodity_list(name_space); cm_list = gnc_commodity_namespace_get_commodity_list(name_space);
i = gtk_tree_path_get_indices (path)[1]; i = gtk_tree_path_get_indices (path)[1];
commodity = g_list_nth_data (cm_list, i); commodity = g_list_nth_data (cm_list, i);
g_list_free (cm_list);
if (!commodity) if (!commodity)
{ {
LEAVE("invalid path at commodity"); LEAVE("invalid path at commodity");
@ -594,9 +596,11 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
gtk_tree_path_append_index (path, g_list_index (ns_list, name_space)); gtk_tree_path_append_index (path, g_list_index (ns_list, name_space));
gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3)); gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
debug_path(LEAVE, path); debug_path(LEAVE, path);
g_list_free (ns_list);
return path; return path;
} }
g_list_free (ns_list);
/* Create a path to the price. */ /* Create a path to the price. */
commodity = gnc_price_get_commodity((GNCPrice*)iter->user_data2); commodity = gnc_price_get_commodity((GNCPrice*)iter->user_data2);
name_space = gnc_commodity_get_namespace_ds(commodity); name_space = gnc_commodity_get_namespace_ds(commodity);
@ -606,6 +610,7 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
gtk_tree_path_append_index (path, g_list_index (cm_list, commodity)); gtk_tree_path_append_index (path, g_list_index (cm_list, commodity));
gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3)); gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
debug_path(LEAVE, path); debug_path(LEAVE, path);
g_list_free (cm_list);
return path; return path;
} }
@ -759,6 +764,7 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
list = gnc_commodity_table_get_namespaces_list(ct); list = gnc_commodity_table_get_namespaces_list(ct);
n = GPOINTER_TO_INT(iter->user_data3) + 1; n = GPOINTER_TO_INT(iter->user_data3) + 1;
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
g_list_free (list);
if (iter->user_data2 == NULL) if (iter->user_data2 == NULL)
{ {
LEAVE("no next iter"); LEAVE("no next iter");
@ -774,6 +780,7 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
n = GPOINTER_TO_INT(iter->user_data3) + 1; n = GPOINTER_TO_INT(iter->user_data3) + 1;
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
g_list_free (list);
if (iter->user_data2 == NULL) if (iter->user_data2 == NULL)
{ {
LEAVE("no next iter"); LEAVE("no next iter");
@ -836,6 +843,7 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, 0); iter->user_data2 = g_list_nth_data(list, 0);
iter->user_data3 = GINT_TO_POINTER(0); iter->user_data3 = GINT_TO_POINTER(0);
LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -854,6 +862,7 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, 0); iter->user_data2 = g_list_nth_data(list, 0);
iter->user_data3 = GINT_TO_POINTER(0); iter->user_data3 = GINT_TO_POINTER(0);
LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -906,7 +915,9 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
name_space = (gnc_commodity_namespace *)iter->user_data2; name_space = (gnc_commodity_namespace *)iter->user_data2;
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
LEAVE("%s children", list ? "has" : "no"); LEAVE("%s children", list ? "has" : "no");
return list != NULL; gboolean rv = (list != NULL);
g_list_free (list);
return rv;
} }
if (iter->user_data == ITER_IS_COMMODITY) if (iter->user_data == ITER_IS_COMMODITY)
@ -943,7 +954,9 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE); ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
list = gnc_commodity_table_get_namespaces_list(ct); list = gnc_commodity_table_get_namespaces_list(ct);
LEAVE("ns list length %d", g_list_length(list)); LEAVE("ns list length %d", g_list_length(list));
return g_list_length (list); guint rv = g_list_length (list);
g_list_free (list);
return rv;
} }
if (iter->user_data == ITER_IS_NAMESPACE) if (iter->user_data == ITER_IS_NAMESPACE)
@ -951,7 +964,9 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
name_space = (gnc_commodity_namespace *)iter->user_data2; name_space = (gnc_commodity_namespace *)iter->user_data2;
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
LEAVE("cm list length %d", g_list_length(list)); LEAVE("cm list length %d", g_list_length(list));
return g_list_length (list); guint rv = g_list_length (list);
g_list_free (list);
return rv;
} }
if (iter->user_data == ITER_IS_COMMODITY) if (iter->user_data == ITER_IS_COMMODITY)
@ -995,6 +1010,7 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
iter->user_data3 = GINT_TO_POINTER(n); iter->user_data3 = GINT_TO_POINTER(n);
LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return iter->user_data2 != NULL; return iter->user_data2 != NULL;
} }
@ -1008,6 +1024,7 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
iter->user_data2 = g_list_nth_data(list, n); iter->user_data2 = g_list_nth_data(list, n);
iter->user_data3 = GINT_TO_POINTER(n); iter->user_data3 = GINT_TO_POINTER(n);
LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return iter->user_data2 != NULL; return iter->user_data2 != NULL;
} }
@ -1064,6 +1081,7 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
iter->user_data2 = name_space; iter->user_data2 = name_space;
iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space)); iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space));
LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("ns iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -1076,6 +1094,7 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
iter->user_data2 = commodity; iter->user_data2 = commodity;
iter->user_data3 = GINT_TO_POINTER(g_list_index(list, commodity)); iter->user_data3 = GINT_TO_POINTER(g_list_index(list, commodity));
LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter)); LEAVE("cm iter %p (%s)", iter, iter_to_string(model, iter));
g_list_free (list);
return TRUE; return TRUE;
} }
@ -1203,6 +1222,7 @@ gnc_tree_model_price_get_iter_from_commodity (GncTreeModelPrice *model,
} }
n = g_list_index(list, commodity); n = g_list_index(list, commodity);
g_list_free (list);
if (n == -1) if (n == -1)
{ {
LEAVE("commodity not in list"); LEAVE("commodity not in list");
@ -1245,6 +1265,7 @@ gnc_tree_model_price_get_iter_from_namespace (GncTreeModelPrice *model,
} }
n = g_list_index(list, name_space); n = g_list_index(list, name_space);
g_list_free (list);
if (n == -1) if (n == -1)
{ {
LEAVE("namespace not found"); LEAVE("namespace not found");

@ -306,7 +306,9 @@ gnc_commodities_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
/* Show any other namespace that has commodities */ /* Show any other namespace that has commodities */
list = gnc_commodity_namespace_get_commodity_list(name_space); list = gnc_commodity_namespace_get_commodity_list(name_space);
return (list != NULL); gboolean rv = (list != NULL);
g_list_free (list);
return rv;
} }
static gboolean static gboolean

@ -635,15 +635,17 @@ gnc_price_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
/* See if this namespace has commodities */ /* See if this namespace has commodities */
auto cm_list = gnc_commodity_namespace_get_commodity_list (name_space); auto cm_list = gnc_commodity_namespace_get_commodity_list (name_space);
for (auto item = cm_list; item; item = g_list_next (item)) auto rv = false;
for (auto item = cm_list; !rv && item; item = g_list_next (item))
{ {
/* For each commodity, see if there are prices */ /* For each commodity, see if there are prices */
auto comm = static_cast<gnc_commodity *> (item->data); auto comm = static_cast<gnc_commodity *> (item->data);
if (gnc_pricedb_has_prices (pdb_dialog->price_db, comm, nullptr)) if (gnc_pricedb_has_prices (pdb_dialog->price_db, comm, nullptr))
return TRUE; rv = true;
} }
return FALSE; g_list_free (cm_list);
return rv;
} }

@ -1008,6 +1008,7 @@ gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
{ {
auto cm_list = gnc_commodity_namespace_get_commodity_list (ns); auto cm_list = gnc_commodity_namespace_get_commodity_list (ns);
g_list_foreach (cm_list, &get_quotables_helper1, (gpointer) &l); g_list_foreach (cm_list, &get_quotables_helper1, (gpointer) &l);
g_list_free (cm_list);
} }
} }
} }

@ -1565,7 +1565,7 @@ gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_s
if (!name_space) if (!name_space)
return nullptr; return nullptr;
return name_space->cm_list; return g_list_copy (name_space->cm_list);
} }
gboolean gboolean
@ -1950,7 +1950,7 @@ gnc_commodity_table_get_namespaces_list(const gnc_commodity_table * table)
if (!table) if (!table)
return nullptr; return nullptr;
return table->ns_list; return g_list_copy (table->ns_list);
} }
/* Because gnc_commodity_table_add_namespace maps GNC_COMMODITY_NS_ISO to /* Because gnc_commodity_table_add_namespace maps GNC_COMMODITY_NS_ISO to

@ -814,7 +814,7 @@ const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace
* @return A pointer to the list of structures. NULL if an invalid * @return A pointer to the list of structures. NULL if an invalid
* argument was supplied. * argument was supplied.
* *
* @note This list is owned by the engine. The caller must not free the list. */ * @note This list is owned by the caller who must free the list. */
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace * ns); GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace * ns);
@ -844,7 +844,7 @@ GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table * t);
* @return A pointer to the list of structures. NULL if an invalid * @return A pointer to the list of structures. NULL if an invalid
* argument was supplied. * argument was supplied.
* *
* @note This list is owned by the engine. The caller must not free the list. */ * @note This list is owned by the caller who must free the list. */
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table * t); GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table * t);
/** This function adds a new string to the list of commodity namespaces. /** This function adds a new string to the list of commodity namespaces.

Loading…
Cancel
Save