make merge_file() use got_path_dirname() instead of assuming const dirname(3) ok naddy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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;
}