[PATCH] erofs-utils: fix memory leak when load compress hints file

Huang Jianan huangjianan at oppo.com
Fri Feb 18 14:11:36 AEDT 2022


Execute fclose before return error.

Signed-off-by: Huang Jianan <huangjianan at oppo.com>
---
 lib/compress_hints.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/compress_hints.c b/lib/compress_hints.c
index c3f3d48..c52e2d3 100644
--- a/lib/compress_hints.c
+++ b/lib/compress_hints.c
@@ -88,6 +88,7 @@ int erofs_load_compress_hints(void)
 	char buf[PATH_MAX + 100];
 	FILE *f;
 	unsigned int line, max_pclustersize = 0;
+	int ret = 0;
 
 	if (!cfg.c_compress_hints_file)
 		return 0;
@@ -105,7 +106,8 @@ int erofs_load_compress_hints(void)
 		if (!pattern || *pattern == '\0') {
 			erofs_err("cannot find a match pattern at line %u",
 				  line);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out;
 		}
 		if (pclustersize % EROFS_BLKSIZ) {
 			erofs_warn("invalid physical clustersize %u, "
@@ -119,10 +121,12 @@ int erofs_load_compress_hints(void)
 		if (pclustersize > max_pclustersize)
 			max_pclustersize = pclustersize;
 	}
-	fclose(f);
+
 	if (cfg.c_pclusterblks_max * EROFS_BLKSIZ < max_pclustersize) {
 		cfg.c_pclusterblks_max = max_pclustersize / EROFS_BLKSIZ;
 		erofs_warn("update max pclusterblks to %u", cfg.c_pclusterblks_max);
 	}
-	return 0;
+out:
+	fclose(f);
+	return ret;
 }
-- 
2.25.1



More information about the Linux-erofs mailing list