Skip to content

Commit 4e2d094

Browse files
Ramsay Jonesgitster
authored andcommitted
Call mkpathdup() rather than xstrdup(mkpath(...))
In addition to updating the xstrdup(mkpath(...)) call sites with mkpathdup(), we also fix a memory leak (in merge_3way()) caused by neglecting to free the memory allocated to the 'base_name' variable. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d292bfa commit 4e2d094

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
196196

197197
free(name);
198198

199-
name = xstrdup(mkpath(fmt, bname.buf));
199+
name = mkpathdup(fmt, bname.buf);
200200
if (read_ref(name, sha1)) {
201201
error(remote_branch
202202
? _("remote branch '%s' not found.")

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
236236
/* Beware: real_path() and mkpath() return static buffer */
237237
ref_git = xstrdup(real_path(item->string));
238238
if (is_directory(mkpath("%s/.git/objects", ref_git))) {
239-
char *ref_git_git = xstrdup(mkpath("%s/.git", ref_git));
239+
char *ref_git_git = mkpathdup("%s/.git", ref_git);
240240
free(ref_git);
241241
ref_git = ref_git_git;
242242
} else if (!is_directory(mkpath("%s/objects", ref_git)))
@@ -700,7 +700,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
700700
git_dir = xstrdup(dir);
701701
else {
702702
work_tree = dir;
703-
git_dir = xstrdup(mkpath("%s/.git", dir));
703+
git_dir = mkpathdup("%s/.git", dir);
704704
}
705705

706706
if (!option_bare) {

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
168168

169169
prune_packed_objects(show_only);
170170
remove_temporary_files(get_object_directory());
171-
s = xstrdup(mkpath("%s/pack", get_object_directory()));
171+
s = mkpathdup("%s/pack", get_object_directory());
172172
remove_temporary_files(s);
173173
free(s);
174174
return 0;

merge-recursive.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,14 +862,14 @@ static int merge_3way(struct merge_options *o,
862862
if (strcmp(a->path, b->path) ||
863863
(o->ancestor != NULL && strcmp(a->path, one->path) != 0)) {
864864
base_name = o->ancestor == NULL ? NULL :
865-
xstrdup(mkpath("%s:%s", o->ancestor, one->path));
866-
name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
867-
name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
865+
mkpathdup("%s:%s", o->ancestor, one->path);
866+
name1 = mkpathdup("%s:%s", branch1, a->path);
867+
name2 = mkpathdup("%s:%s", branch2, b->path);
868868
} else {
869869
base_name = o->ancestor == NULL ? NULL :
870-
xstrdup(mkpath("%s", o->ancestor));
871-
name1 = xstrdup(mkpath("%s", branch1));
872-
name2 = xstrdup(mkpath("%s", branch2));
870+
mkpathdup("%s", o->ancestor);
871+
name1 = mkpathdup("%s", branch1);
872+
name2 = mkpathdup("%s", branch2);
873873
}
874874

875875
read_mmblob(&orig, one->sha1);
@@ -879,6 +879,7 @@ static int merge_3way(struct merge_options *o,
879879
merge_status = ll_merge(result_buf, a->path, &orig, base_name,
880880
&src1, name1, &src2, name2, &ll_opts);
881881

882+
free(base_name);
882883
free(name1);
883884
free(name2);
884885
free(orig.ptr);

0 commit comments

Comments
 (0)