Commit 3524bbf95aa21318b6fff23c10b26ac57d1ab374

Stefan Sperling 2020-10-20T21:09:01

make merge_file() use got_path_dirname() instead of assuming const dirname(3) ok naddy

diff --git a/lib/worktree.c b/lib/worktree.c
index 8495e38..c29ea7c 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -782,18 +782,20 @@ merge_file(int *local_changes_subsumed, struct got_worktree *worktree,
 	char *blob_orig_path = NULL;
 	char *merged_path = NULL, *base_path = NULL;
 	int overlapcnt = 0;
-	char *parent;
+	char *parent = NULL;
 	char *symlink_path = NULL;
 	FILE *symlinkf = NULL;
 
 	*local_changes_subsumed = 0;
 
-	parent = dirname(ondisk_path);
-	if (parent == NULL)
-		return got_error_from_errno2("dirname", ondisk_path);
+	err = got_path_dirname(&parent, ondisk_path);
+	if (err)
+		return err;
 
-	if (asprintf(&base_path, "%s/got-merged", parent) == -1)
-		return got_error_from_errno("asprintf");
+	if (asprintf(&base_path, "%s/got-merged", parent) == -1) {
+		err = got_error_from_errno("asprintf");
+		goto done;
+	}
 
 	err = got_opentemp_named_fd(&merged_path, &merged_fd, base_path);
 	if (err)
@@ -914,6 +916,7 @@ done:
 		unlink(blob_orig_path);
 		free(blob_orig_path);
 	}
+	free(parent);
 	return err;
 }