@@ -75,10 +75,12 @@ int cmd_init_db(int argc,
75
75
const char * prefix ,
76
76
struct repository * repo UNUSED )
77
77
{
78
- const char * git_dir ;
78
+ char * git_dir ;
79
79
const char * real_git_dir = NULL ;
80
- const char * work_tree ;
80
+ char * real_git_dir_to_free = NULL ;
81
+ char * work_tree = NULL ;
81
82
const char * template_dir = NULL ;
83
+ char * template_dir_to_free = NULL ;
82
84
unsigned int flags = 0 ;
83
85
const char * object_format = NULL ;
84
86
const char * ref_format = NULL ;
@@ -106,19 +108,18 @@ int cmd_init_db(int argc,
106
108
N_ ("specify the reference format to use" )),
107
109
OPT_END ()
108
110
};
111
+ int ret ;
109
112
110
113
argc = parse_options (argc , argv , prefix , init_db_options , init_db_usage , 0 );
111
114
112
115
if (real_git_dir && is_bare_repository_cfg == 1 )
113
116
die (_ ("options '%s' and '%s' cannot be used together" ), "--separate-git-dir" , "--bare" );
114
117
115
118
if (real_git_dir && !is_absolute_path (real_git_dir ))
116
- real_git_dir = real_pathdup (real_git_dir , 1 );
119
+ real_git_dir = real_git_dir_to_free = real_pathdup (real_git_dir , 1 );
117
120
118
- if (template_dir && * template_dir && !is_absolute_path (template_dir )) {
119
- template_dir = absolute_pathdup (template_dir );
120
- UNLEAK (template_dir );
121
- }
121
+ if (template_dir && * template_dir && !is_absolute_path (template_dir ))
122
+ template_dir = template_dir_to_free = absolute_pathdup (template_dir );
122
123
123
124
if (argc == 1 ) {
124
125
int mkdir_tried = 0 ;
@@ -192,7 +193,7 @@ int cmd_init_db(int argc,
192
193
* Set up the default .git directory contents
193
194
*/
194
195
if (!git_dir )
195
- git_dir = DEFAULT_GIT_DIR_ENVIRONMENT ;
196
+ git_dir = xstrdup ( DEFAULT_GIT_DIR_ENVIRONMENT ) ;
196
197
197
198
/*
198
199
* When --separate-git-dir is used inside a linked worktree, take
@@ -213,6 +214,7 @@ int cmd_init_db(int argc,
213
214
if (chdir (mainwt .buf ) < 0 )
214
215
die_errno (_ ("cannot chdir to %s" ), mainwt .buf );
215
216
strbuf_release (& mainwt );
217
+ free (git_dir );
216
218
git_dir = strbuf_detach (& sb , NULL );
217
219
}
218
220
strbuf_release (& sb );
@@ -245,12 +247,14 @@ int cmd_init_db(int argc,
245
247
set_git_work_tree (work_tree );
246
248
}
247
249
248
- UNLEAK (real_git_dir );
249
- UNLEAK (git_dir );
250
- UNLEAK (work_tree );
251
-
252
250
flags |= INIT_DB_EXIST_OK ;
253
- return init_db (git_dir , real_git_dir , template_dir , hash_algo ,
254
- ref_storage_format , initial_branch ,
255
- init_shared_repository , flags );
251
+ ret = init_db (git_dir , real_git_dir , template_dir , hash_algo ,
252
+ ref_storage_format , initial_branch ,
253
+ init_shared_repository , flags );
254
+
255
+ free (template_dir_to_free );
256
+ free (real_git_dir_to_free );
257
+ free (work_tree );
258
+ free (git_dir );
259
+ return ret ;
256
260
}
0 commit comments