[LTP] [PATCH v2] lib/tst_memutils.c: Fix resource leak

Bogdan Lezhepekov blezhepekov@suse.de
Tue Feb 15 14:31:10 CET 2022


File descriptor was not closed properly
before return.

Signed-off-by: Bogdan Lezhepekov <blezhepekov@suse.de>
---
 lib/tst_memutils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 4a4974761..3741d6e6f 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -121,8 +121,10 @@ static int write_score(const char *path, int score)
 	if (!f)
 		return 1;
 
-	if (fprintf(f, "%d", score) <= 0)
+	if (fprintf(f, "%d", score) <= 0) {
+		fclose(f);
 		return 1;
+	}
 
 	if (fclose(f))
 		return 1;
-- 
2.35.1



More information about the ltp mailing list