git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fsck: free buffers on error in fsck_obj()

From
René Scharfe <l.s.r@web.de>
Date
Aug 10, 2017, 09:42 UTC
Message-ID
<c7f5b84b-b7b7-c9ed-601d-686b37ffe61c@web.de>

Move the code for releasing tree buffers and commit buffers in fsck_obj() to the end of the function and make sure it's executed no matter of an error is encountered or not.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/fsck.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 99dea7adf6..698a8776a4 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -335,6 +335,8 @@ static void check_connectivity(void)
 
 static int fsck_obj(struct object *obj)
 {
+	int err;
+
 	if (obj->flags & SEEN)
 		return 0;
 	obj->flags |= SEEN;
@@ -345,20 +347,13 @@ static int fsck_obj(struct object *obj)
 
 	if (fsck_walk(obj, NULL, &fsck_obj_options))
 		objerror(obj, "broken links");
-	if (fsck_object(obj, NULL, 0, &fsck_obj_options))
-		return -1;
-
-	if (obj->type == OBJ_TREE) {
-		struct tree *item = (struct tree *) obj;
-
-		free_tree_buffer(item);
-	}
+	err = fsck_object(obj, NULL, 0, &fsck_obj_options);
+	if (err)
+		goto out;
 
 	if (obj->type == OBJ_COMMIT) {
 		struct commit *commit = (struct commit *) obj;
 
-		free_commit_buffer(commit);
-
 		if (!commit->parents && show_root)
 			printf("root %s\n", describe_object(&commit->object));
 	}
@@ -374,7 +369,12 @@ static int fsck_obj(struct object *obj)
 		}
 	}
 
-	return 0;
+out:
+	if (obj->type == OBJ_TREE)
+		free_tree_buffer((struct tree *)obj);
+	if (obj->type == OBJ_COMMIT)
+		free_commit_buffer((struct commit *)obj);
+	return err;
 }
 
 static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
-- 
2.14.0
Next: Jeff King
Message 1 of 2 in “fsck: free buffers on error in fsck_obj()”
  1. fsck: free buffers on error in fsck_obj()René Scharfe, Aug 10, 2017
  2. Jeff KingAug 11, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.