Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-08-10 12:35:38 +0300
committerJunio C Hamano <gitster@pobox.com>2015-08-11 01:37:12 +0300
commite3cf230324f740653d4fb4a3087c2daf9da62029 (patch)
treea463f382e6d547ae669948bf4a40175be3063113 /refs.c
parentfcd12db6af118b70b5c15cf5fdd6800eeecc370a (diff)
prefer mkpathdup to mkpath in assignments
As with the previous commit to git_path, assigning the result of mkpath is suspicious, since it is not clear whether we will still depend on the value after it may have been overwritten by subsequent calls. This patch converts low-hanging fruit to use mkpathdup instead of mkpath (with the downside that we must remember to free the result). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index 93b250e754..e70941a090 100644
--- a/refs.c
+++ b/refs.c
@@ -3380,7 +3380,7 @@ static int commit_ref_update(struct ref_lock *lock,
int create_symref(const char *ref_target, const char *refs_heads_master,
const char *logmsg)
{
- const char *lockpath;
+ char *lockpath = NULL;
char ref[1000];
int fd, len, written;
char *git_HEAD = git_pathdup("%s", ref_target);
@@ -3407,7 +3407,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
error("refname too long: %s", refs_heads_master);
goto error_free_return;
}
- lockpath = mkpath("%s.lock", git_HEAD);
+ lockpath = mkpathdup("%s.lock", git_HEAD);
fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd < 0) {
error("Unable to open %s for writing", lockpath);
@@ -3427,9 +3427,11 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
error_unlink_return:
unlink_or_warn(lockpath);
error_free_return:
+ free(lockpath);
free(git_HEAD);
return -1;
}
+ free(lockpath);
#ifndef NO_SYMLINK_HEAD
done: