Skip to content

Commit

Permalink
[test] Fix memory leak in test-gnc-quotes
Browse files Browse the repository at this point in the history
When the commodity table is registered, the current book will get
a default table assigned.  When later setting the table explicitly
using qof_book_set_data() the exisiting table gets overwritten and
is thus leaked.

There is no way of removing or freeing a currency table from a book,
so the best we can do here is to set our own table on the book before
calling gnc_commodity_table_register().
  • Loading branch information
mkbosmans authored and jralls committed Apr 29, 2023
1 parent 6be682b commit 71802b5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libgnucash/app-utils/test/gtest-gnc-quotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ class GncQuotesTest : public ::testing::Test
m_book{qof_session_get_book(gnc_get_current_session())}
{
qof_init();
gnc_commodity_table_register();
gnc_pricedb_register();

/* By setting an empty commodity table on the book before registering
* the commodity_table type we avoid adding the default commodities */
auto comm_table{gnc_commodity_table_new()};
qof_book_set_data(m_book, GNC_COMMODITY_TABLE, comm_table);

gnc_commodity_table_register();
gnc_pricedb_register();

auto eur = gnc_commodity_new(m_book, "Euro", "ISO4217", "EUR", NULL, 100);
auto source{gnc_quote_source_lookup_by_internal("currency")};
gnc_commodity_begin_edit(eur);
Expand Down

0 comments on commit 71802b5

Please sign in to comment.