builtin/fast-import: plug trivial memory leaks

Plug some trivial memory leaks in git-fast-import(1). Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 14, 2024 at 08:52 UTC 0662f0dacb59de2aa56f41c7d8645784c2174ca7
3 files changed +9 -2
builtin/fast-import.c
+6 -2
@@ -206,8 +206,8 @@ static unsigned int object_entry_alloc = 5000;
206 static struct object_entry_pool *blocks;
207 static struct hashmap object_table;
208 static struct mark_set *marks;
209 -static const char *export_marks_file;
210 -static const char *import_marks_file;
209 +static char *export_marks_file;
210 +static char *import_marks_file;
211 static int import_marks_file_from_stream;
212 static int import_marks_file_ignore_missing;
213 static int import_marks_file_done;
@@ -3274,6 +3274,7 @@ static void option_import_marks(const char *marks,
3274 read_marks();
3275 }
3276
3277 + free(import_marks_file);
3278 import_marks_file = make_fast_import_path(marks);
3279 import_marks_file_from_stream = from_stream;
3280 import_marks_file_ignore_missing = ignore_missing;
@@ -3316,6 +3317,7 @@ static void option_active_branches(const char *branches)
3317
3318 static void option_export_marks(const char *marks)
3319 {
3320 + free(export_marks_file);
3321 export_marks_file = make_fast_import_path(marks);
3322 }
3323
@@ -3357,6 +3359,8 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)
3359 free(f);
3360
3361 string_list_insert(list, s)->util = ms;
3362 +
3363 + free(s);
3364 }
3365
3366 static int parse_one_option(const char *option)
t/t9300-fast-import.sh
+1
@@ -7,6 +7,7 @@ test_description='test git fast-import utility'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10 +TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
13
t/t9304-fast-import-marks.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='test exotic situations with marks'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup dump of basic history' '