From: Christian Couder Date: Thu, 30 Mar 2017 06:22:08 +0000 (+0200) Subject: update-index: fix xgetcwd() related memory leak X-Git-Tag: v2.13.0-rc0~31^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c105f563d1b8894af8a7bee68852e45831d55224?ds=inline;hp=--cc 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 Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- c105f563d1b8894af8a7bee68852e45831d55224 diff --git a/builtin/update-index.c b/builtin/update-index.c index 7a5533491e..984fe37da1 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);