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_save(s, NULL);
qof_session_end(s);
qof_session_destroy(s);
unlink(TESTFILE);
return 0;
}

View File

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

View File

@ -57,6 +57,9 @@ test_string_converters (void)
do_test_args (
g_strcmp0 (backout, mark) == 0,
"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,
"string sanitizing", __FILE__, __LINE__,
"with string %s", badstr);
g_free (backout);
xmlFreeNode (test_node);
}
int

View File

@ -19,7 +19,8 @@
\********************************************************************/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include "test-engine-stuff.h"
#include "io-gncxml-v2.h"
@ -38,11 +39,9 @@ main (int argc, char** argv)
directory = "test-files/xml2";
}
auto size{strlen (directory) + 1 + strlen (FILENAME) + 1};
char* filename = static_cast<decltype (filename)> (malloc (size));
snprintf (filename, size, "%s/%s", directory, FILENAME);
do_test (gnc_is_xml_data_file_v2 (filename, NULL), "gnc_is_xml_data_file_v2");
auto filename = std::string{directory} + '/' + FILENAME;
do_test (gnc_is_xml_data_file_v2 (filename.c_str(), NULL), "gnc_is_xml_data_file_v2");
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
* test error messages should then show the system's temporary
* directory to be used instead */
home_dir = argv[1];
home_dir = g_strdup (argv[1]);
else
/* Set up a fake home directory to play with */
home_dir = g_dir_make_tmp("gnucashXXXXXX", NULL);
@ -105,6 +105,7 @@ main(int argc, char **argv)
g_free(daout);
}
g_free (home_dir);
print_test_results();
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
* directory in that case. */
g_setenv("HOME", homedir, TRUE);
g_free (homedir);
for (i = 0; strs2[i].funcname != NULL; i++)
{
char *daout;

View File

@ -52,6 +52,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <string>
#include <qof.h>
#include "Account.h"
@ -1376,8 +1379,6 @@ get_random_transaction_with_currency(QofBook *book,
{
Transaction* trans;
KvpFrame *f;
gint num;
gchar *numstr;
if (!account_list)
{
@ -1392,8 +1393,6 @@ get_random_transaction_with_currency(QofBook *book,
return NULL;
}
numstr = g_new0(gchar, 10);
trans = xaccMallocTransaction(book);
xaccTransBeginEdit(trans);
@ -1402,9 +1401,10 @@ get_random_transaction_with_currency(QofBook *book,
currency ? currency :
get_random_commodity (book));
num = get_random_int_in_range (1, max_trans_num);
g_snprintf(numstr, 10, "%d", num);
xaccTransSetNum(trans, numstr);
gint num = get_random_int_in_range (1, max_trans_num);
auto numstr = std::to_string(num);
xaccTransSetNum(trans, numstr.c_str());
set_tran_random_string_from_array(trans, xaccTransSetDescription,
sane_descriptions);
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_EQ (NULL, pdata->guids->next);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
g_list_free_full (guidlist, (GDestroyNotify)guid_free);
}
TEST_F(QofQueryCoreTest, construct_predicate_int32)