git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsck: free buffers on error in fsck_obj()
@ 2017-08-10  9:42 René Scharfe
  2017-08-11 10:22 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2017-08-10  9:42 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fsck: free buffers on error in fsck_obj()
  2017-08-10  9:42 [PATCH] fsck: free buffers on error in fsck_obj() René Scharfe
@ 2017-08-11 10:22 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2017-08-11 10:22 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Thu, Aug 10, 2017 at 11:42:10AM +0200, René Scharfe wrote:

> 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.

This looks good to me.

> @@ -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;
>  }

The second one could be "else if". But then, the same could be said of
the rest of the function (and fsck_object() that we call). It probably
doesn't really matter in practice.

-Peff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-11 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-10  9:42 [PATCH] fsck: free buffers on error in fsck_obj() René Scharfe
2017-08-11 10:22 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).