summaryrefslogtreecommitdiff
path: root/builtin/fsck.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-08-22 17:29:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-08-22 17:29:14 (GMT)
commit2d68161a230a6a713ac0f4ad68c51cc856e83338 (patch)
tree7d479c43701e0ae40884bd3e851cda4e32278a76 /builtin/fsck.c
parent2893137b0d967ea1a5282aeb9874aea0aa49ec8d (diff)
parent83cd6f901762f7358c0b249d8e7efd5476ab66d4 (diff)
downloadgit-2d68161a230a6a713ac0f4ad68c51cc856e83338.zip
git-2d68161a230a6a713ac0f4ad68c51cc856e83338.tar.gz
git-2d68161a230a6a713ac0f4ad68c51cc856e83338.tar.bz2
Merge branch 'rs/fsck-obj-leakfix'
Memory leak in an error codepath has been plugged. * rs/fsck-obj-leakfix: fsck: free buffers on error in fsck_obj()
Diffstat (limited to 'builtin/fsck.c')
-rw-r--r--builtin/fsck.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index a92f448..b0964a8 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -326,6 +326,8 @@ static void check_connectivity(void)
static int fsck_obj(struct object *obj)
{
+ int err;
+
if (obj->flags & SEEN)
return 0;
obj->flags |= SEEN;
@@ -336,20 +338,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));
}
@@ -365,7 +360,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,