examples/ntb: fix resource leaks

Message ID 20190814060725.43129-1-xiaoyun.li@intel.com (mailing list archive)
State Superseded, archived
Headers
Series examples/ntb: fix resource leaks |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-Compile-Testing success Compile Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Li, Xiaoyun Aug. 14, 2019, 6:07 a.m. UTC
  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")
Cc: stable@dpdk.org

Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
---
 examples/ntb/ntb_fwd.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Xiaolong Ye Aug. 14, 2019, 6:50 a.m. UTC | #1
On 08/14, Xiaoyun Li wrote:
>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")
>Cc: stable@dpdk.org
>
>Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
>---
> examples/ntb/ntb_fwd.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
>index f8c970cdb..bf8a73547 100644
>--- a/examples/ntb/ntb_fwd.c
>+++ b/examples/ntb/ntb_fwd.c
>@@ -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;
> 	}
> 
>-- 
>2.17.1
>

Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
  

Patch

diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
index f8c970cdb..bf8a73547 100644
--- a/examples/ntb/ntb_fwd.c
+++ b/examples/ntb/ntb_fwd.c
@@ -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;
 	}