Skip to content

Commit 83cd6f9

Browse files
rscharfegitster
authored andcommitted
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>
1 parent 3d9c5b5 commit 83cd6f9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

builtin/fsck.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ static void check_connectivity(void)
335335

336336
static int fsck_obj(struct object *obj)
337337
{
338+
int err;
339+
338340
if (obj->flags & SEEN)
339341
return 0;
340342
obj->flags |= SEEN;
@@ -345,20 +347,13 @@ static int fsck_obj(struct object *obj)
345347

346348
if (fsck_walk(obj, NULL, &fsck_obj_options))
347349
objerror(obj, "broken links");
348-
if (fsck_object(obj, NULL, 0, &fsck_obj_options))
349-
return -1;
350-
351-
if (obj->type == OBJ_TREE) {
352-
struct tree *item = (struct tree *) obj;
353-
354-
free_tree_buffer(item);
355-
}
350+
err = fsck_object(obj, NULL, 0, &fsck_obj_options);
351+
if (err)
352+
goto out;
356353

357354
if (obj->type == OBJ_COMMIT) {
358355
struct commit *commit = (struct commit *) obj;
359356

360-
free_commit_buffer(commit);
361-
362357
if (!commit->parents && show_root)
363358
printf("root %s\n", describe_object(&commit->object));
364359
}
@@ -374,7 +369,12 @@ static int fsck_obj(struct object *obj)
374369
}
375370
}
376371

377-
return 0;
372+
out:
373+
if (obj->type == OBJ_TREE)
374+
free_tree_buffer((struct tree *)obj);
375+
if (obj->type == OBJ_COMMIT)
376+
free_commit_buffer((struct commit *)obj);
377+
return err;
378378
}
379379

380380
static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,

0 commit comments

Comments
 (0)