Thread (183 messages) 183 messages, 9 authors, 2022-06-11

[PATCH v6 1/6] object-file.c: release strbuf in write_loose_object()

STALE1578d

From: Han Xin <hidden>
Date: 2021-12-17 11:28:43
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v5 of 4 in this series.

Revisions (4)
  1. v5 current
  2. v5 [diff vs current]
  3. v5 [diff vs current]
  4. v8 [diff vs current]
From: Han Xin <redacted>

Fix a strbuf leak in "write_loose_object()" sugguested by
Ævar Arnfjörð Bjarmason.

Helped-by: Ævar Arnfjörð Bjarmason [off-list ref]
Signed-off-by: Han Xin <redacted>
---
 object-file.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/object-file.c b/object-file.c
index eb1426f98c..32acf1dad6 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1874,11 +1874,14 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
 	fd = create_tmpfile(&tmp_file, filename.buf);
 	if (fd < 0) {
 		if (flags & HASH_SILENT)
-			return -1;
+			ret = -1;
 		else if (errno == EACCES)
-			return error(_("insufficient permission for adding an object to repository database %s"), get_object_directory());
+			ret = error(_("insufficient permission for adding an "
+				      "object to repository database %s"),
+				    get_object_directory());
 		else
-			return error_errno(_("unable to create temporary file"));
+			ret = error_errno(_("unable to create temporary file"));
+		goto cleanup;
 	}
 
 	/* Set it up */
@@ -1930,7 +1933,11 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
 			warning_errno(_("failed utime() on %s"), tmp_file.buf);
 	}
 
-	return finalize_object_file(tmp_file.buf, filename.buf);
+	ret = finalize_object_file(tmp_file.buf, filename.buf);
+cleanup:
+	strbuf_release(&filename);
+	strbuf_release(&tmp_file);
+	return ret;
 }
 
 static int freshen_loose_object(const struct object_id *oid)
-- 
2.34.1.52.gfcc2252aea.agit.6.5.6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help