Skip to content

Commit

Permalink
ModuleStreamV1: Fix memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
  • Loading branch information
sgallagher committed Feb 5, 2020
1 parent 995f0c3 commit 3ec0d8c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions modulemd/modulemd-module-stream-v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
41 changes: 41 additions & 0 deletions modulemd/tests/test-modulemd-modulestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
{
Expand Down Expand Up @@ -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 ();
}

0 comments on commit 3ec0d8c

Please sign in to comment.