summaryrefslogtreecommitdiff
path: root/builtin/update-index.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2017-03-30 06:22:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-30 17:33:31 (GMT)
commitc105f563d1b8894af8a7bee68852e45831d55224 (patch)
treec95f4f5a0970fd03f1a393cbaaea9608c3c6d953 /builtin/update-index.c
parent7c121788f4c93a29dbec0d61b3cd986a757a5077 (diff)
downloadgit-c105f563d1b8894af8a7bee68852e45831d55224.zip
git-c105f563d1b8894af8a7bee68852e45831d55224.tar.gz
git-c105f563d1b8894af8a7bee68852e45831d55224.tar.bz2
update-index: fix xgetcwd() related memory leak
As xgetcwd() returns an allocated buffer, we should free this buffer when we don't need it any more. This was found by Coverity. Reported-by: Jeff King <peff@peff.net> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-index.c')
-rw-r--r--builtin/update-index.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 7a55334..984fe37 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -125,12 +125,16 @@ static int test_if_untracked_cache_is_supported(void)
struct stat st;
struct stat_data base;
int fd, ret = 0;
+ char *cwd;
strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
if (!mkdtemp(mtime_dir.buf))
die_errno("Could not make temporary directory");
- fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd());
+ cwd = xgetcwd();
+ fprintf(stderr, _("Testing mtime in '%s' "), cwd);
+ free(cwd);
+
atexit(remove_test_directory);
xstat_mtime_dir(&st);
fill_stat_data(&base, &st);