Skip to contentSkip to conversation

examples/ntb: fix resource leaks

PATCH In review Xiaoyun Li 2 participants 2 messages Aug 14, 2019

lore
Share & tools
lore

Xiaoyun Li

author
#0 lore raw

PATCH 1/1 examples/ntb: fix resource leaks

Resource file was not freed or pointed-to in fseek/ftell. This patch fixed this issue which is found by coverity scan.

Coverity issue: 347277

Fixes 440af660ff83 ("examples/ntb: fix error handling")
---
 examples/ntb/ntb_fwd.c | 2 ++
 1 file changed, 2 insertions(+)
examples/ntb/ntb_fwd.c +2 -0
index f8c970cdb..bf8a73547 100644
@@ -127,11 +127,13 @@ cmd_sendfile_parsed(void *parsed_result,
 
 	if (fseek(file, 0, SEEK_END) < 0) {
 		printf("Fail to get file size.\n");
+		fclose(file);
 		return;
 	}
 	size = ftell(file);
 	if (fseek(file, 0, SEEK_SET) < 0) {
 		printf("Fail to get file size.\n");
+		fclose(file);
 		return;
 	}
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Xiaoyun Li

Resource file was not freed or pointed-to in fseek/ftell. This patch fixed this issue which is found by coverity scan.

Coverity issue: 347277

Fixes 440af660ff83 ("examples/ntb: fix error handling")

---
examples/ntb/ntb_fwd.c | 2 ++

1 file changed, 2 insertions(+)
examples/ntb/ntb_fwd.c +2 -0
index f8c970cdb..bf8a73547 100644
@@ -127,11 +127,13 @@ cmd_sendfile_parsed(void *parsed_result,
 
 	if (fseek(file, 0, SEEK_END) < 0) {
 		printf("Fail to get file size.\n");
+		fclose(file);
 		return;
 	}
 	size = ftell(file);
 	if (fseek(file, 0, SEEK_SET) < 0) {
 		printf("Fail to get file size.\n");
+		fclose(file);
 		return;
 	}
 
Signature · 1 line
2.17.1