Skip to contentSkip to conversation

fsck: fix leak when traversing trees

PATCH In review Eric Wong 2 participants 2 messages Jan 20, 2018 – Jan 23, 2018

lore
Share & tools
lore

Eric Wong

author
#0 lore raw

PATCH 1/1 fsck: fix leak when traversing trees

While fsck_walk/fsck_walk_tree/parse_tree populates "struct tree" idempotently, it is still up to the fsck_walk caller to call free_tree_buffer.

Fixes ad2db4030e42890e ("fsck: remove redundant parse_tree() invocation")

---
These APIs could probably be made to be less error-prone, but at least this stops my little machine from OOM-ing.

 builtin/fsck.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
builtin/fsck.c +7 -1
index 04846d46f9..92ce775a74 100644
@@ -171,7 +171,13 @@ static void mark_object_reachable(struct object *obj)
 
 static int traverse_one_object(struct object *obj)
 {
-	return fsck_walk(obj, obj, &fsck_walk_options);
+	int result = fsck_walk(obj, obj, &fsck_walk_options);
+
+	if (obj->type == OBJ_TREE) {
+		struct tree *tree = (struct tree *)obj;
+		free_tree_buffer(tree);
+	}
+	return result;
 }
 
 static int traverse_reachable(void)
Signature · 1 line
EW
#1 lore raw
Quoted 5 lines · Eric Wong

While fsck_walk/fsck_walk_tree/parse_tree populates "struct tree" idempotently, it is still up to the fsck_walk caller to call free_tree_buffer.

Fixes ad2db4030e42890e ("fsck: remove redundant parse_tree() invocation")

Yup, we can see that that commit did stop freeing the tree buffer. Thanks.

Quoted 28 lines

---
These APIs could probably be made to be less error-prone, but at least this stops my little machine from OOM-ing.

 builtin/fsck.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
builtin/fsck.c +7 -1
index 04846d46f9..92ce775a74 100644
@@ -171,7 +171,13 @@ static void mark_object_reachable(struct object *obj)
 
 static int traverse_one_object(struct object *obj)
 {
-	return fsck_walk(obj, obj, &fsck_walk_options);
+	int result = fsck_walk(obj, obj, &fsck_walk_options);
+
+	if (obj->type == OBJ_TREE) {
+		struct tree *tree = (struct tree *)obj;
+		free_tree_buffer(tree);
+	}
+	return result;
 }
 
 static int traverse_reachable(void)