Skip to content

Commit c105f56

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c12178 commit c105f56

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

builtin/update-index.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,16 @@ static int test_if_untracked_cache_is_supported(void)
125125
struct stat st;
126126
struct stat_data base;
127127
int fd, ret = 0;
128+
char *cwd;
128129

129130
strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
130131
if (!mkdtemp(mtime_dir.buf))
131132
die_errno("Could not make temporary directory");
132133

133-
fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd());
134+
cwd = xgetcwd();
135+
fprintf(stderr, _("Testing mtime in '%s' "), cwd);
136+
free(cwd);
137+
134138
atexit(remove_test_directory);
135139
xstat_mtime_dir(&st);
136140
fill_stat_data(&base, &st);

0 commit comments

Comments
 (0)