[ASAN] tests: Fix leaks

Just for cleaner sanitizer output.

Closes: #598
Approved by: jlebon
This commit is contained in:
Colin Walters 2016-11-28 22:03:53 -05:00 committed by Atomic Bot
parent 667b734c79
commit 62b94635bc
5 changed files with 20 additions and 8 deletions

View File

@ -73,7 +73,6 @@ test_raw_file_to_archive_z2_stream (gconstpointer data)
&commit_checksum,
&error);
g_assert_no_error (error);
reachable = ostree_repo_traverse_new_reachable ();
ostree_repo_traverse_commit (repo,
commit_checksum,
-1,

View File

@ -31,7 +31,7 @@ static GKeyFile *g_keyfile;
static void
test_get_boolean_with_default (void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
gboolean out = FALSE;
GLogLevelFlags always_fatal_mask;
@ -46,18 +46,21 @@ test_get_boolean_with_default (void)
FALSE,
&out,
&error));
g_clear_error (&error);
g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
NULL,
"a_boolean_true",
FALSE,
&out,
&error));
g_clear_error (&error);
g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
"section",
NULL,
FALSE,
&out,
&error));
g_clear_error (&error);
/* Restore the old mask. */
g_log_set_always_fatal (always_fatal_mask);
@ -86,6 +89,7 @@ test_get_boolean_with_default (void)
&error));
g_assert_true (out);
g_clear_error (&error);
g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
"a_fake_section",
"a_boolean_true",
@ -97,8 +101,8 @@ test_get_boolean_with_default (void)
static void
test_get_value_with_default (void)
{
GError *error = NULL;
char *out = NULL;
g_autoptr(GError) error = NULL;
g_autofree char *out = NULL;
GLogLevelFlags always_fatal_mask;
const char *section = "section";
@ -112,18 +116,21 @@ test_get_value_with_default (void)
"none",
&out,
&error));
g_clear_pointer (&out, g_free);
g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
section,
NULL,
"none",
&out,
&error));
g_clear_pointer (&out, g_free);
g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
section,
NULL,
"something",
&out,
&error));
g_clear_pointer (&out, g_free);
/* Restore the old mask. */
g_log_set_always_fatal (always_fatal_mask);
@ -135,6 +142,7 @@ test_get_value_with_default (void)
&out,
&error));
g_assert_cmpstr (out, ==, "foo");
g_clear_pointer (&out, g_free);
g_assert (ot_keyfile_get_value_with_default (g_keyfile,
section,
@ -143,6 +151,7 @@ test_get_value_with_default (void)
&out,
&error));
g_assert_cmpstr (out, ==, "correct");
g_clear_pointer (&out, g_free);
g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
"a_fake_section",
@ -150,6 +159,8 @@ test_get_value_with_default (void)
"no value",
&out,
&error));
g_clear_error (&error);
g_clear_pointer (&out, g_free);
}
static void

View File

@ -180,7 +180,7 @@ static void
test_libarchive_autocreate_empty (gconstpointer data)
{
TestData *td = (void*)data;
GError *error = NULL;
g_autoptr(GError) error = NULL;
struct archive *a = archive_read_new ();
OstreeRepoImportArchiveOptions opts = { 0, };
glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
@ -198,7 +198,7 @@ static void
test_libarchive_error_device_file (gconstpointer data)
{
TestData *td = (void*)data;
GError *error = NULL;
g_autoptr(GError) error = NULL;
struct archive *a = archive_read_new ();
OstreeRepoImportArchiveOptions opts = { 0, };
glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
@ -563,6 +563,7 @@ int main (int argc, char **argv)
r = g_test_run();
g_clear_object (&td.repo);
if (td.tmpd && g_getenv ("TEST_SKIP_CLEANUP") == NULL)
(void) glnx_shutil_rm_rf_at (AT_FDCWD, td.tmpd, NULL, NULL);
g_free (td.tmpd);

View File

@ -127,6 +127,7 @@ int main (int argc, char **argv)
g_test_add_data_func ("/test-pull-c/multi-ok-error-repeat", &td, test_pull_multi_error_then_ok);
r = g_test_run();
g_clear_object (&td.repo);
return r;
}

View File

@ -74,8 +74,8 @@ test_rollsum (void)
#define MAX_BUFFER_SIZE 1000000
gsize i;
int len;
unsigned char *a = malloc (MAX_BUFFER_SIZE);
unsigned char *b = malloc (MAX_BUFFER_SIZE);
g_autofree unsigned char *a = malloc (MAX_BUFFER_SIZE);
g_autofree unsigned char *b = malloc (MAX_BUFFER_SIZE);
g_autoptr(GRand) rand = g_rand_new ();
/* These two buffers produce the same crc32. */