{"thread":{"id":"46553","subject":"[PATCH] fsck: free buffers on error in fsck_obj()","startedAt":"2017-08-10T09:42:23Z","lastAt":"2017-08-11T10:22:18Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"326022","messageId":"c7f5b84b-b7b7-c9ed-601d-686b37ffe61c@web.de","threadId":"46553","inReplyTo":null,"subject":"[PATCH] fsck: free buffers on error in fsck_obj()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-08-10T09:42:10Z","receivedAt":"2017-08-10T09:42:23Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Move the code for releasing tree buffers and commit buffers in\nfsck_obj() to the end of the function and make sure it's executed no\nmatter of an error is encountered or not.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/fsck.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 99dea7adf6..698a8776a4 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -335,6 +335,8 @@ static void check_connectivity(void)\n \n static int fsck_obj(struct object *obj)\n {\n+\tint err;\n+\n \tif (obj->flags & SEEN)\n \t\treturn 0;\n \tobj->flags |= SEEN;\n@@ -345,20 +347,13 @@ static int fsck_obj(struct object *obj)\n \n \tif (fsck_walk(obj, NULL, &fsck_obj_options))\n \t\tobjerror(obj, \"broken links\");\n-\tif (fsck_object(obj, NULL, 0, &fsck_obj_options))\n-\t\treturn -1;\n-\n-\tif (obj->type == OBJ_TREE) {\n-\t\tstruct tree *item = (struct tree *) obj;\n-\n-\t\tfree_tree_buffer(item);\n-\t}\n+\terr = fsck_object(obj, NULL, 0, &fsck_obj_options);\n+\tif (err)\n+\t\tgoto out;\n \n \tif (obj->type == OBJ_COMMIT) {\n \t\tstruct commit *commit = (struct commit *) obj;\n \n-\t\tfree_commit_buffer(commit);\n-\n \t\tif (!commit->parents && show_root)\n \t\t\tprintf(\"root %s\\n\", describe_object(&commit->object));\n \t}\n@@ -374,7 +369,12 @@ static int fsck_obj(struct object *obj)\n \t\t}\n \t}\n \n-\treturn 0;\n+out:\n+\tif (obj->type == OBJ_TREE)\n+\t\tfree_tree_buffer((struct tree *)obj);\n+\tif (obj->type == OBJ_COMMIT)\n+\t\tfree_commit_buffer((struct commit *)obj);\n+\treturn err;\n }\n \n static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,\n-- \n2.14.0\n"},{"id":"326141","messageId":"20170811102211.iqyfdro5zywtdj3n@sigill.intra.peff.net","threadId":"46553","inReplyTo":"c7f5b84b-b7b7-c9ed-601d-686b37ffe61c@web.de","subject":"Re: [PATCH] fsck: free buffers on error in fsck_obj()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-08-11T10:22:12Z","receivedAt":"2017-08-11T10:22:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 10, 2017 at 11:42:10AM +0200, René Scharfe wrote:\n\n> Move the code for releasing tree buffers and commit buffers in\n> fsck_obj() to the end of the function and make sure it's executed no\n> matter of an error is encountered or not.\n\nThis looks good to me.\n\n> @@ -374,7 +369,12 @@ static int fsck_obj(struct object *obj)\n>  \t\t}\n>  \t}\n>  \n> -\treturn 0;\n> +out:\n> +\tif (obj->type == OBJ_TREE)\n> +\t\tfree_tree_buffer((struct tree *)obj);\n> +\tif (obj->type == OBJ_COMMIT)\n> +\t\tfree_commit_buffer((struct commit *)obj);\n> +\treturn err;\n>  }\n\nThe second one could be \"else if\". But then, the same could be said of\nthe rest of the function (and fsck_object() that we call). It probably\ndoesn't really matter in practice.\n\n-Peff\n"}]}