diff --git a/modulemd/modulemd-module-stream-v1.c b/modulemd/modulemd-module-stream-v1.c index b74251fd5..d4c6a9688 100644 --- a/modulemd/modulemd-module-stream-v1.c +++ b/modulemd/modulemd-module-stream-v1.c @@ -1923,6 +1923,7 @@ modulemd_module_stream_v1_parse_licenses (yaml_parser_t *parser, set = modulemd_yaml_parse_string_set (parser, &nested_error); modulemd_module_stream_v1_replace_content_licenses (modulestream, set); + g_clear_pointer (&set, g_hash_table_unref); } else { diff --git a/modulemd/tests/test-modulemd-modulestream.c b/modulemd/tests/test-modulemd-modulestream.c index 40464c5bb..f63509e46 100644 --- a/modulemd/tests/test-modulemd-modulestream.c +++ b/modulemd/tests/test-modulemd-modulestream.c @@ -3138,6 +3138,44 @@ module_stream_v2_test_community (void) g_clear_object (&stream); } + +/* + * This is a regression test for a memory leak that occurred when reading a + * v1 ModuleStream YAML document if the `data.license.content` field appeared + * before the `data.license.module` field. + */ +static void +module_stream_v1_regression_content_license (void) +{ + g_autoptr (ModulemdModuleStream) stream = NULL; + g_autoptr (GError) error = NULL; + const char *content_first = + "---\n" + "document: modulemd\n" + "version: 1\n" + "data:\n" + " summary: summary\n" + " description: >-\n" + " desc\n" + " license:\n" + " content:\n" + " - BSD\n" + " module:\n" + " - MIT\n" + " xmd:\n" + " something:\n" + " - foo\n" + " - bar\n" + "...\n"; + + stream = modulemd_module_stream_read_string ( + content_first, TRUE, NULL, NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (stream); + g_assert_true (MODULEMD_IS_MODULE_STREAM_V1 (stream)); +} + + int main (int argc, char *argv[]) { @@ -3289,5 +3327,8 @@ main (int argc, char *argv[]) g_test_add_func ("/modulemd/v2/modulestream/v2/xmd/issue290plus", module_stream_v2_test_xmd_issue_290_with_example); + g_test_add_func ("/modulemd/v2/modulestream/regression/memleak/v1_licenses", + module_stream_v1_regression_content_license); + return g_test_run (); }