Skip to content

Commit 04fe4d7

Browse files
ahuntgitster
authored andcommitted
init-db: silence template_dir leak when converting to absolute path
template_dir starts off pointing to either argv or nothing. However if the value supplied in argv is a relative path, absolute_pathdup() is used to turn it into an absolute path. absolute_pathdup() allocates a new string, and we then "leak" it when cmd_init_db() completes. We don't bother to actually free the return value (instead we UNLEAK it), because there's no significant advantage to doing so here. Correctly freeing it would require more significant changes to code flow which would be more noisy than beneficial. Signed-off-by: Andrzej Hunt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4de450 commit 04fe4d7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/init-db.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
561561
if (real_git_dir && !is_absolute_path(real_git_dir))
562562
real_git_dir = real_pathdup(real_git_dir, 1);
563563

564-
if (template_dir && *template_dir && !is_absolute_path(template_dir))
564+
if (template_dir && *template_dir && !is_absolute_path(template_dir)) {
565565
template_dir = absolute_pathdup(template_dir);
566+
UNLEAK(template_dir);
567+
}
566568

567569
if (argc == 1) {
568570
int mkdir_tried = 0;

0 commit comments

Comments
 (0)