load_one_loose_object_map(): fix resource leak

Pointed out by Coverity.

While at it, reduce near-duplicate clean-up code at the end of the
function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2026-07-05 08:24:18 +00:00
committed by Junio C Hamano
parent e9019fcafe
commit 8b90835161

View File

@@ -65,6 +65,7 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
int ret = -1;
if (!loose->map)
loose_object_map_init(&loose->map);
@@ -84,7 +85,6 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
return 0;
}
errno = 0;
if (strbuf_getwholeline(&buf, fp, '\n') || strcmp(buf.buf, loose_object_header))
goto err;
while (!strbuf_getline_lf(&buf, fp)) {
@@ -98,13 +98,12 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
insert_loose_map(loose, &oid, &compat_oid);
}
strbuf_release(&buf);
strbuf_release(&path);
return errno ? -1 : 0;
ret = ferror(fp) ? -1 : 0;
err:
fclose(fp);
strbuf_release(&buf);
strbuf_release(&path);
return -1;
return ret;
}
int repo_read_loose_object_map(struct repository *repo)