Skip to content

Commit 2d68161

Browse files
committed
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()
2 parents 2893137 + 83cd6f9 commit 2d68161

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
@@ -326,6 +326,8 @@ static void check_connectivity(void)
326326

327327
static int fsck_obj(struct object *obj)
328328
{
329+
int err;
330+
329331
if (obj->flags & SEEN)
330332
return 0;
331333
obj->flags |= SEEN;
@@ -336,20 +338,13 @@ static int fsck_obj(struct object *obj)
336338

337339
if (fsck_walk(obj, NULL, &fsck_obj_options))
338340
objerror(obj, "broken links");
339-
if (fsck_object(obj, NULL, 0, &fsck_obj_options))
340-
return -1;
341-
342-
if (obj->type == OBJ_TREE) {
343-
struct tree *item = (struct tree *) obj;
344-
345-
free_tree_buffer(item);
346-
}
341+
err = fsck_object(obj, NULL, 0, &fsck_obj_options);
342+
if (err)
343+
goto out;
347344

348345
if (obj->type == OBJ_COMMIT) {
349346
struct commit *commit = (struct commit *) obj;
350347

351-
free_commit_buffer(commit);
352-
353348
if (!commit->parents && show_root)
354349
printf("root %s\n", describe_object(&commit->object));
355350
}
@@ -365,7 +360,12 @@ static int fsck_obj(struct object *obj)
365360
}
366361
}
367362

368-
return 0;
363+
out:
364+
if (obj->type == OBJ_TREE)
365+
free_tree_buffer((struct tree *)obj);
366+
if (obj->type == OBJ_COMMIT)
367+
free_commit_buffer((struct commit *)obj);
368+
return err;
369369
}
370370

371371
static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,

0 commit comments

Comments
 (0)