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

Bogdan Lezhepekov bogdan.lezhepekov@suse.com
Fri Feb 11 16:27:51 CET 2022


File descriptor was not closed properly
before return.

Signed-off-by: Bogdan Lezhepekov <bogdan.lezhepekov@suse.com>
---
 lib/tst_memutils.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 4a4974761..2e6d7d5fd 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -122,7 +122,10 @@ static int write_score(const char *path, int score)
 		return 1;
 
 	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