[PATCH v1 3/7] erofs-utils: lib: Fix memory leak if __erofs_battach() fails

Sandeep Dhavale dhavale at google.com
Thu Sep 14 08:11:00 AEST 2023


Need to free allocated buffer_head bh if __erofs_battach() fails.

Signed-off-by: Sandeep Dhavale <dhavale at google.com>
---
 lib/cache.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/cache.c b/lib/cache.c
index 5205d57..a9948f0 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -282,8 +282,10 @@ struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size,
 
 	ret = __erofs_battach(bb, bh, size, alignsize,
 			      required_ext + inline_ext, false);
-	if (ret < 0)
+	if (ret < 0) {
+		free(bh);
 		return ERR_PTR(ret);
+	}
 	return bh;
 }
 
-- 
2.42.0.283.g2d96d420d3-goog



More information about the Linux-erofs mailing list