From e1c48c8adbd14f8767d44d46b1a7a5f896ab1129 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 2 Dec 2016 13:45:04 -0500 Subject: [PATCH] [ASAN] tests: Cleanup all current remaining leaks We now run fully through ASAN here. Closes: #609 Approved by: jlebon --- tests/test-bsdiff.c | 4 +++- tests/test-lzma.c | 7 ++++--- tests/test-mutable-tree.c | 10 ++++++---- tests/test-ot-opt-utils.c | 6 +++--- tests/test-ot-tool-util.c | 7 +++++-- tests/test-ot-unix-utils.c | 13 ++++++++++--- tests/test-varint.c | 2 +- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/tests/test-bsdiff.c b/tests/test-bsdiff.c index 5c5eb104..24772a1e 100644 --- a/tests/test-bsdiff.c +++ b/tests/test-bsdiff.c @@ -89,7 +89,9 @@ test_bsdiff (void) g_output_stream_close (out, NULL, NULL); /* Now generate NEW_GENERATED from OLD and OUT. */ - in = g_memory_input_stream_new_from_bytes (g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out))); + { g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out)); + in = g_memory_input_stream_new_from_bytes (bytes); + } bspatch_stream.read = bzpatch_read; bspatch_stream.opaque = in; diff --git a/tests/test-lzma.c b/tests/test-lzma.c index 8d37d47f..1f7d2559 100644 --- a/tests/test-lzma.c +++ b/tests/test-lzma.c @@ -32,7 +32,7 @@ static void helper_test_compress_decompress (const guint8 *data, gssize data_size) { - GError *error = NULL; + g_autoptr(GError) error = NULL; g_autoptr(GOutputStream) out_compress = g_memory_output_stream_new_resizable (); g_autoptr(GOutputStream) out_decompress = NULL; g_autoptr(GInputStream) in_compress = g_memory_input_stream_new_from_data (data, data_size, NULL); @@ -55,9 +55,10 @@ helper_test_compress_decompress (const guint8 *data, gssize data_size) { gssize n_bytes_written; g_autoptr(GInputStream) convin = NULL; - g_autoptr(GConverter) decompressor = (GConverter*)_ostree_lzma_decompressor_new (); + g_autoptr(GConverter) decompressor = (GConverter*)_ostree_lzma_decompressor_new (); + g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress)); - in_decompress = g_memory_input_stream_new_from_bytes (g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress))); + in_decompress = g_memory_input_stream_new_from_bytes (bytes); convin = g_converter_input_stream_new ((GInputStream*) in_decompress, decompressor); n_bytes_written = g_output_stream_splice (out_decompress, convin, G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, diff --git a/tests/test-mutable-tree.c b/tests/test-mutable-tree.c index b357f691..9df36ac6 100644 --- a/tests/test-mutable-tree.c +++ b/tests/test-mutable-tree.c @@ -84,7 +84,7 @@ test_ensure_parent_dirs (void) glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *parent = NULL; g_autoptr(GPtrArray) split_path = NULL; - GError *error = NULL; + g_autoptr(GError) error = NULL; const char *pathname = "/foo/bar/baz"; const char *checksum = "01234567890123456789012345678901"; g_autofree char *source_checksum = NULL; @@ -103,6 +103,7 @@ test_ensure_parent_dirs (void) g_assert_false (ostree_mutable_tree_lookup (tree, "bar", &source_checksum2, &source_subdir2, &error)); + g_clear_error (&error); } static void @@ -110,7 +111,7 @@ test_ensure_dir (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *parent = NULL; - GError *error = NULL; + g_autoptr(GError) error = NULL; const char *dirname = "foo"; const char *filename = "bar"; const char *checksum = "01234567890123456789012345678901"; @@ -122,13 +123,14 @@ test_ensure_dir (void) g_assert (ostree_mutable_tree_replace_file (tree, filename, checksum, &error)); g_assert_false (ostree_mutable_tree_ensure_dir (tree, filename, &parent, &error)); + g_clear_error (&error); } static void test_replace_file (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); - GError *error = NULL; + g_autoptr(GError) error = NULL; const char *filename = "bar"; const char *checksum = "01234567890123456789012345678901"; const char *checksum2 = "ABCDEF01234567890123456789012345"; @@ -157,7 +159,7 @@ test_contents_checksum (void) const char *subdir_checksum = "ABCD0123456789012345678901234567"; glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *subdir = NULL; - GError *error = NULL; + g_autoptr(GError) error = NULL; g_assert_null (ostree_mutable_tree_get_contents_checksum (tree)); ostree_mutable_tree_set_contents_checksum (tree, checksum); diff --git a/tests/test-ot-opt-utils.c b/tests/test-ot-opt-utils.c index 1a7230b3..77ecdf30 100644 --- a/tests/test-ot-opt-utils.c +++ b/tests/test-ot-opt-utils.c @@ -40,19 +40,19 @@ util_usage_error_printerr (const gchar *string) static void test_ot_util_usage_error (void) { - GError *error = NULL; - GOptionContext *context = g_option_context_new ("[TEST]"); + g_autoptr(GError) error = NULL; + g_autoptr(GOptionContext) context = g_option_context_new ("[TEST]"); GPrintFunc old_printerr = g_set_printerr_handler (util_usage_error_printerr); ot_util_usage_error (context, "find_me", &error); g_assert_nonnull (strstr (printerr_str->str, "[TEST]")); g_assert_nonnull (strstr (error->message, "find_me")); + g_clear_error (&error); g_set_printerr_handler (old_printerr); g_string_free (printerr_str, TRUE); printerr_str = NULL; - g_option_context_free (context); } int main (int argc, char **argv) diff --git a/tests/test-ot-tool-util.c b/tests/test-ot-tool-util.c index e63a0185..13030fe4 100644 --- a/tests/test-ot-tool-util.c +++ b/tests/test-ot-tool-util.c @@ -43,7 +43,7 @@ ot_parse_keyvalue (const char *keyvalue, static void test_ot_parse_boolean (void) { - GError *error = NULL; + g_autoptr(GError) error = NULL; gboolean out = FALSE; g_assert_true (ot_parse_boolean ("yes", &out, &error)); g_assert_true (out); @@ -70,15 +70,17 @@ test_ot_parse_boolean (void) out = TRUE; g_assert_true (ot_parse_boolean ("none", &out, &error)); g_assert_false (out); + g_clear_error (&error); g_assert_false (ot_parse_boolean ("FOO", &out, &error)); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED); + g_clear_error (&error); } static void test_ot_parse_keyvalue (void) { - GError *error = NULL; + g_autoptr(GError) error = NULL; char *keyvalue[] = {"foo=bar", "a=", "b=1231231"}; char *key[] = {"foo", "a", "b"}; char *value[] = {"bar", "", "1231231"}; @@ -104,6 +106,7 @@ test_ot_parse_keyvalue (void) &out_value, &error)); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED); + g_clear_error (&error); } } diff --git a/tests/test-ot-unix-utils.c b/tests/test-ot-unix-utils.c index 6c77d2a2..5eeab1d1 100644 --- a/tests/test-ot-unix-utils.c +++ b/tests/test-ot-unix-utils.c @@ -50,22 +50,29 @@ test_ot_util_path_split_validate (void) static void test_ot_util_filename_validate (void) { - GError *error = NULL; + g_autoptr(GError) error = NULL; /* Check for valid inputs. */ g_assert (ot_util_filename_validate ("valid", &error)); + g_assert_no_error (error); g_assert (ot_util_filename_validate ("valid_file_name", &error)); + g_assert_no_error (error); g_assert (ot_util_filename_validate ("file.name", &error)); + g_assert_no_error (error); g_assert (ot_util_filename_validate ("foo..", &error)); + g_assert_no_error (error); g_assert (ot_util_filename_validate ("..bar", &error)); + g_assert_no_error (error); g_assert (ot_util_filename_validate ("baz:", &error)); + g_assert_no_error (error); /* Check for invalid inputs. */ g_assert_false (ot_util_filename_validate ("not/valid/file/name", &error)); - error = NULL; + g_clear_error (&error); g_assert_false (ot_util_filename_validate (".", &error)); - error = NULL; + g_clear_error (&error); g_assert_false (ot_util_filename_validate ("..", &error)); + g_clear_error (&error); } int main (int argc, char **argv) diff --git a/tests/test-varint.c b/tests/test-varint.c index 76f85573..062c47ef 100644 --- a/tests/test-varint.c +++ b/tests/test-varint.c @@ -27,7 +27,7 @@ static void check_one_roundtrip (guint64 val) { - GString *buf = g_string_new (NULL); + g_autoptr(GString) buf = g_string_new (NULL); guint64 newval; gsize bytes_read;