1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-30 13:57:54 +01:00

fsck: free buffers on error in fsck_obj()

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2017-08-10 11:42:10 +02:00 committed by Junio C Hamano
parent 3d9c5b5c44
commit 83cd6f9017

View file

@ -335,6 +335,8 @@ static void check_connectivity(void)
static int fsck_obj(struct object *obj) static int fsck_obj(struct object *obj)
{ {
int err;
if (obj->flags & SEEN) if (obj->flags & SEEN)
return 0; return 0;
obj->flags |= SEEN; obj->flags |= SEEN;
@ -345,20 +347,13 @@ static int fsck_obj(struct object *obj)
if (fsck_walk(obj, NULL, &fsck_obj_options)) if (fsck_walk(obj, NULL, &fsck_obj_options))
objerror(obj, "broken links"); objerror(obj, "broken links");
if (fsck_object(obj, NULL, 0, &fsck_obj_options)) err = fsck_object(obj, NULL, 0, &fsck_obj_options);
return -1; if (err)
goto out;
if (obj->type == OBJ_TREE) {
struct tree *item = (struct tree *) obj;
free_tree_buffer(item);
}
if (obj->type == OBJ_COMMIT) { if (obj->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *) obj; struct commit *commit = (struct commit *) obj;
free_commit_buffer(commit);
if (!commit->parents && show_root) if (!commit->parents && show_root)
printf("root %s\n", describe_object(&commit->object)); 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 unsigned char *sha1, enum object_type type, static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,