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>
René Scharfe committed
Aug 10, 2017 at 11:42 UTC
83cd6f901762f7358c0b249d8e7efd5476ab66d4
1 file changed
+11
-11
builtin/fsck.c
+11
-11
@@ -335,6 +335,8 @@ static void check_connectivity(void)
335
336
static int fsck_obj(struct object *obj)
337
{
338
+ int err;
339
+
340
if (obj->flags & SEEN)
341
return 0;
342
obj->flags |= SEEN;
@@ -345,20 +347,13 @@ static int fsck_obj(struct object *obj)
347
348
if (fsck_walk(obj, NULL, &fsck_obj_options))
349
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;
353
354
if (obj->type == OBJ_COMMIT) {
355
struct commit *commit = (struct commit *) obj;
356
360
- free_commit_buffer(commit);
361
-
357
if (!commit->parents && show_root)
358
printf("root %s\n", describe_object(&commit->object));
359
}
@@ -374,7 +369,12 @@ static int fsck_obj(struct object *obj)
369
}
370
}
371
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;
378
}
379
380
static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,