read_index_from(): avoid memory leak

In 998330ac2e7c (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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 15, 2022 at 23:35 UTC 652891de4ff164d545daa5472ab67f4f9d41319b
1 file changed +3 -3
read-cache.c
+3 -3
@@ -2473,15 +2473,15 @@ int read_index_from(struct index_state *istate, const char *path,
2473 the_repository, "%s", base_path);
2474 if (!ret) {
2475 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);
2478 free(path_copy);
2479 trace2_region_enter_printf("index", "shared/do_read_index",
2480 the_repository, "%s", base_path2);
2481 ret = do_read_index(split_index->base, base_path2, 1);
2482 trace2_region_leave_printf("index", "shared/do_read_index",
2483 the_repository, "%s", base_path2);
2484 + free(base_path2);
2485 }
2486 if (!oideq(&split_index->base_oid, &split_index->base->oid))
2487 die(_("broken index, expect %s in %s, got %s"),