merge-recursive: Remember to free generated unique path names
Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Aug 11, 2011 at 23:19 UTC
3d6b8e884c45e65e0abda431690cd4b3bcaf04f0
1 file changed
+12
-8
merge-recursive.c
+12
-8
@@ -1061,7 +1061,6 @@ static int process_renames(struct merge_options *o,
1061
renamed: clean merge */
1062
update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
1063
} else if (!sha_eq(dst_other.sha1, null_sha1)) {
1064
- const char *new_path;
1064
clean_merge = 0;
1065
try_merge = 1;
1066
output(o, 1, "CONFLICT (rename/add): Rename %s->%s in %s. "
@@ -1090,9 +1089,10 @@ static int process_renames(struct merge_options *o,
1089
ren1_dst);
1090
try_merge = 0;
1091
} else {
1093
- new_path = unique_path(o, ren1_dst, branch2);
1092
+ char *new_path = unique_path(o, ren1_dst, branch2);
1093
output(o, 1, "Adding as %s instead", new_path);
1094
update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
1095
+ free(new_path);
1096
}
1097
} else if ((item = string_list_lookup(renames2Dst, ren1_dst))) {
1098
ren2 = item->util;
@@ -1260,13 +1260,14 @@ static int merge_content(struct merge_options *o,
1260
}
1261
1262
if (df_conflict_remains) {
1263
- const char *new_path;
1263
+ char *new_path;
1264
update_file_flags(o, mfi.sha, mfi.mode, path,
1265
o->call_depth || mfi.clean, 0);
1266
new_path = unique_path(o, path, df_rename_conflict_branch);
1267
mfi.clean = 0;
1268
output(o, 1, "Adding as %s instead", new_path);
1269
update_file_flags(o, mfi.sha, mfi.mode, new_path, 0, 1);
1270
+ free(new_path);
1271
} else {
1272
update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1273
}
@@ -1422,12 +1423,14 @@ static int process_df_entry(struct merge_options *o,
1423
}
1424
} else if (o_sha && (!a_sha || !b_sha)) {
1425
/* Modify/delete; deleted side may have put a directory in the way */
1425
- const char *new_path = path;
1426
- if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode))
1427
- new_path = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
1426
+ char *renamed = NULL;
1427
+ if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
1428
+ renamed = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
1429
+ }
1430
clean_merge = 0;
1429
- handle_delete_modify(o, path, new_path,
1431
+ handle_delete_modify(o, path, renamed ? renamed : path,
1432
a_sha, a_mode, b_sha, b_mode);
1433
+ free(renamed);
1434
} else if (!o_sha && !!a_sha != !!b_sha) {
1435
/* directory -> (directory, file) or <nothing> -> (directory, file) */
1436
const char *add_branch;
@@ -1450,12 +1453,13 @@ static int process_df_entry(struct merge_options *o,
1453
conf = "directory/file";
1454
}
1455
if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
1453
- const char *new_path = unique_path(o, path, add_branch);
1456
+ char *new_path = unique_path(o, path, add_branch);
1457
clean_merge = 0;
1458
output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
1459
"Adding %s as %s",
1460
conf, path, other_branch, path, new_path);
1461
update_file(o, 0, sha, mode, new_path);
1462
+ free(new_path);
1463
} else {
1464
output(o, 2, "Adding %s", path);
1465
update_file(o, 1, sha, mode, path);