Thread (40 messages) 40 messages, 5 authors, 1d ago

Re: [PATCH 01/13] load_one_loose_object_map(): fix resource leak

From: Junio C Hamano <hidden>
Date: 2026-07-01 16:25:21

"Johannes Schindelin via GitGitGadget" [off-list ref]
writes:
quoted hunk ↗ jump to hunk
From: Johannes Schindelin <redacted>

Pointed out by Coverity.

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

Signed-off-by: Johannes Schindelin <redacted>
---
 loose.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/loose.c b/loose.c
index 0b626c1b85..47b7f5ec38 100644
--- a/loose.c
+++ b/loose.c
@@ -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);
@@ -98,13 +99,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;
Wow, this is bad bad bad.  We do not even know what is in errno as
we are supposed to have jumped to out-of-line err label in all error
cases.
+	ret = 0;
Or we can do

	ret = ferror(fp) ? -1 : 0;

if we want to be sure that we have caught all the errors.
 err:
+	fclose(fp);
 	strbuf_release(&buf);
 	strbuf_release(&path);
-	return -1;
+	return ret;
 }
 
 int repo_read_loose_object_map(struct repository *repo)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help