Skip to contentSkip to conversation

lib/tst_memutils.c: Fix resource leak

PATCH In review Bogdan Lezhepekov 2 participants 2 messages Feb 15, 2022 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib/tst_memutils.c: Fix resource leak

File descriptor was not closed properly
before return.

---
 lib/tst_memutils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/tst_memutils.c +3 -1
index 4a4974761..3741d6e6f 100644
@@ -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;
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp