Merge Richard Cohen branch 'fix-leaks-in-tests' into stable #1713

This commit is contained in:
Christopher Lam 2023-07-24 13:09:55 +08:00
commit 867867da53
8 changed files with 25 additions and 14 deletions

View File

@ -36,6 +36,7 @@ int main()
qof_session_load(s, NULL); qof_session_load(s, NULL);
qof_session_save(s, NULL); qof_session_save(s, NULL);
qof_session_end(s); qof_session_end(s);
qof_session_destroy(s);
unlink(TESTFILE); unlink(TESTFILE);
return 0; return 0;
} }

View File

@ -156,6 +156,7 @@ protected:
m_import_acc->free(); m_import_acc->free();
m_dest_acc->free(); m_dest_acc->free();
m_trans->free(); m_trans->free();
g_list_free (m_splitList);
m_split->free(); m_split->free();
} }

View File

@ -57,6 +57,9 @@ test_string_converters (void)
do_test_args ( do_test_args (
g_strcmp0 (backout, mark) == 0, g_strcmp0 (backout, mark) == 0,
"string converting", __FILE__, __LINE__, "with string %s", mark); "string converting", __FILE__, __LINE__, "with string %s", mark);
g_free (backout);
xmlFreeNode (test_node);
} }
} }
@ -71,6 +74,9 @@ test_bad_string (void)
do_test_args (g_strcmp0 (backout, sanitized) == 0, do_test_args (g_strcmp0 (backout, sanitized) == 0,
"string sanitizing", __FILE__, __LINE__, "string sanitizing", __FILE__, __LINE__,
"with string %s", badstr); "with string %s", badstr);
g_free (backout);
xmlFreeNode (test_node);
} }
int int

View File

@ -19,7 +19,8 @@
\********************************************************************/ \********************************************************************/
#include <config.h> #include <config.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <string>
#include "test-engine-stuff.h" #include "test-engine-stuff.h"
#include "io-gncxml-v2.h" #include "io-gncxml-v2.h"
@ -38,11 +39,9 @@ main (int argc, char** argv)
directory = "test-files/xml2"; directory = "test-files/xml2";
} }
auto size{strlen (directory) + 1 + strlen (FILENAME) + 1}; auto filename = std::string{directory} + '/' + FILENAME;
char* filename = static_cast<decltype (filename)> (malloc (size)); do_test (gnc_is_xml_data_file_v2 (filename.c_str(), NULL), "gnc_is_xml_data_file_v2");
snprintf (filename, size, "%s/%s", directory, FILENAME);
do_test (gnc_is_xml_data_file_v2 (filename, NULL), "gnc_is_xml_data_file_v2");
print_test_results (); print_test_results ();
exit (get_rv ()); return get_rv ();
} }

View File

@ -65,7 +65,7 @@ main(int argc, char **argv)
* used to pass invalid home directories manually. The * used to pass invalid home directories manually. The
* test error messages should then show the system's temporary * test error messages should then show the system's temporary
* directory to be used instead */ * directory to be used instead */
home_dir = argv[1]; home_dir = g_strdup (argv[1]);
else else
/* Set up a fake home directory to play with */ /* Set up a fake home directory to play with */
home_dir = g_dir_make_tmp("gnucashXXXXXX", NULL); home_dir = g_dir_make_tmp("gnucashXXXXXX", NULL);
@ -105,6 +105,7 @@ main(int argc, char **argv)
g_free(daout); g_free(daout);
} }
g_free (home_dir);
print_test_results(); print_test_results();
return get_rv(); return get_rv();
} }

View File

@ -83,6 +83,8 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
* The code should fall back to using the temporary * The code should fall back to using the temporary
* directory in that case. */ * directory in that case. */
g_setenv("HOME", homedir, TRUE); g_setenv("HOME", homedir, TRUE);
g_free (homedir);
for (i = 0; strs2[i].funcname != NULL; i++) for (i = 0; strs2[i].funcname != NULL; i++)
{ {
char *daout; char *daout;

View File

@ -52,6 +52,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string>
#include <qof.h> #include <qof.h>
#include "Account.h" #include "Account.h"
@ -1376,8 +1379,6 @@ get_random_transaction_with_currency(QofBook *book,
{ {
Transaction* trans; Transaction* trans;
KvpFrame *f; KvpFrame *f;
gint num;
gchar *numstr;
if (!account_list) if (!account_list)
{ {
@ -1392,8 +1393,6 @@ get_random_transaction_with_currency(QofBook *book,
return NULL; return NULL;
} }
numstr = g_new0(gchar, 10);
trans = xaccMallocTransaction(book); trans = xaccMallocTransaction(book);
xaccTransBeginEdit(trans); xaccTransBeginEdit(trans);
@ -1402,9 +1401,10 @@ get_random_transaction_with_currency(QofBook *book,
currency ? currency : currency ? currency :
get_random_commodity (book)); get_random_commodity (book));
num = get_random_int_in_range (1, max_trans_num); gint num = get_random_int_in_range (1, max_trans_num);
g_snprintf(numstr, 10, "%d", num); auto numstr = std::to_string(num);
xaccTransSetNum(trans, numstr); xaccTransSetNum(trans, numstr.c_str());
set_tran_random_string_from_array(trans, xaccTransSetDescription, set_tran_random_string_from_array(trans, xaccTransSetDescription,
sane_descriptions); sane_descriptions);
trn_add_ran_time(trans, xaccTransSetDatePostedSecs); trn_add_ran_time(trans, xaccTransSetDatePostedSecs);

View File

@ -102,6 +102,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_guid)
EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data)); EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data));
EXPECT_EQ (NULL, pdata->guids->next); EXPECT_EQ (NULL, pdata->guids->next);
qof_query_core_predicate_free ((QofQueryPredData*) pdata); qof_query_core_predicate_free ((QofQueryPredData*) pdata);
g_list_free_full (guidlist, (GDestroyNotify)guid_free);
} }
TEST_F(QofQueryCoreTest, construct_predicate_int32) TEST_F(QofQueryCoreTest, construct_predicate_int32)