Skip to contentSkip to conversation

lib/tst_memutils.c: Fix resource leak

PATCH In review Bogdan Lezhepekov via ltp 2 participants 2 messages Feb 11, 2022 – Feb 15, 2022 Library code

lore
Share & tools
lore
#0 lore raw

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

File descriptor was not closed properly
before return.

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

lib/tst_memutils.c static int write_score(const char *path, int score) · line 128

Quoted 12 lines
lib/tst_memutils.c +3 -0
index 4a4974761..2e6d7d5fd 100644
@@ -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;
+	}

The coding style is wrong. Please run 'make check' in the respective directory when the source code located and fix all warnings.

Quoted 8 lines
lib/tst_memutils.c +0 -0
 	if (fclose(f))
 		return 1;
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

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