Commit fdcb7dafaba4486c7faede6ba199e2024b269b1f

Stefan Sperling 2019-12-15T11:15:48

always unlink merged temporary files if an error occurs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/lib/worktree.c b/lib/worktree.c
index dfe5cb1..a8f6827 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -810,11 +810,13 @@ merge_file(int *local_changes_subsumed, struct got_worktree *worktree,
 	if (rename(merged_path, ondisk_path) != 0) {
 		err = got_error_from_errno3("rename", merged_path,
 		    ondisk_path);
-		unlink(merged_path);
 		goto done;
 	}
-
 done:
+	if (err) {
+		if (merged_path)
+			unlink(merged_path);
+	}
 	if (merged_fd != -1 && close(merged_fd) != 0 && err == NULL)
 		err = got_error_from_errno("close");
 	if (f_orig && fclose(f_orig) != 0 && err == NULL)