Skip to content

Commit 652891d

Browse files
dschogitster
authored andcommitted
read_index_from(): avoid memory leak
In 998330a (read-cache: look for shared index files next to the index, too, 2021-08-26), we added code that allocates memory to store the base path of a shared index, but we never released that memory. Reported by Coverity. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41a86b6 commit 652891d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,15 +2473,15 @@ int read_index_from(struct index_state *istate, const char *path,
24732473
the_repository, "%s", base_path);
24742474
if (!ret) {
24752475
char *path_copy = xstrdup(path);
2476-
const char *base_path2 = xstrfmt("%s/sharedindex.%s",
2477-
dirname(path_copy),
2478-
base_oid_hex);
2476+
char *base_path2 = xstrfmt("%s/sharedindex.%s",
2477+
dirname(path_copy), base_oid_hex);
24792478
free(path_copy);
24802479
trace2_region_enter_printf("index", "shared/do_read_index",
24812480
the_repository, "%s", base_path2);
24822481
ret = do_read_index(split_index->base, base_path2, 1);
24832482
trace2_region_leave_printf("index", "shared/do_read_index",
24842483
the_repository, "%s", base_path2);
2484+
free(base_path2);
24852485
}
24862486
if (!oideq(&split_index->base_oid, &split_index->base->oid))
24872487
die(_("broken index, expect %s in %s, got %s"),

0 commit comments

Comments
 (0)