diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-07-09 11:34:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-07-09 11:34:05 -0700 |
commit | 3b8e8af187cb86ed030432f1a067121fdd4b1c3b (patch) | |
tree | dd8cdaa18cfd70d6cfe6b0a3120fccb5f0a971cd /walker.c | |
parent | e91ae32a01ffe294b8510c1d8cd7138493a0712f (diff) | |
parent | cb6c38d5cce7d8d48a57346b332a68cea1489df1 (diff) |
Merge branch 'jk/xstrfmt'
* jk/xstrfmt:
setup_git_env(): introduce git_path_from_env() helper
unique_path: fix unlikely heap overflow
walker_fetch: fix minor memory leak
merge: use argv_array when spawning merge strategy
sequencer: use argv_array_pushf
setup_git_env: use git_pathdup instead of xmalloc + sprintf
use xstrfmt to replace xmalloc + strcpy/strcat
use xstrfmt to replace xmalloc + sprintf
use xstrdup instead of xmalloc + strcpy
use xstrfmt in favor of manual size calculations
strbuf: add xstrfmt helper
Diffstat (limited to 'walker.c')
-rw-r--r-- | walker.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -253,7 +253,8 @@ int walker_fetch(struct walker *walker, int targets, char **target, { struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *)); unsigned char *sha1 = xmalloc(targets * 20); - char *msg; + const char *msg; + char *to_free = NULL; int ret; int i; @@ -285,21 +286,19 @@ int walker_fetch(struct walker *walker, int targets, char **target, if (loop(walker)) goto unlock_and_fail; - if (write_ref_log_details) { - msg = xmalloc(strlen(write_ref_log_details) + 12); - sprintf(msg, "fetch from %s", write_ref_log_details); - } else { - msg = NULL; - } + if (write_ref_log_details) + msg = to_free = xstrfmt("fetch from %s", write_ref_log_details); + else + msg = "fetch (unknown)"; for (i = 0; i < targets; i++) { if (!write_ref || !write_ref[i]) continue; - ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)"); + ret = write_ref_sha1(lock[i], &sha1[20 * i], msg); lock[i] = NULL; if (ret) goto unlock_and_fail; } - free(msg); + free(to_free); return 0; @@ -307,6 +306,7 @@ unlock_and_fail: for (i = 0; i < targets; i++) if (lock[i]) unlock_ref(lock[i]); + free(to_free); return -1; } |