[dpdk-dev] net/nfp: fix resource leak

Message ID 1510143253-9860-1-git-send-email-alejandro.lucero@netronome.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Alejandro Lucero Nov. 8, 2017, 12:14 p.m. UTC
  File descriptor is not released in any potential exit path
inside the function.

Fixes: f37d8a4b67b2 ("net/nfp: add NSP FW upload command")
Coverity: 195018

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 drivers/net/nfp/nfp_nspu.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Ferruh Yigit Nov. 10, 2017, 9:39 a.m. UTC | #1
On 11/8/2017 4:14 AM, Alejandro Lucero wrote:
> File descriptor is not released in any potential exit path
> inside the function.
> 
> Fixes: f37d8a4b67b2 ("net/nfp: add NSP FW upload command")
> Coverity: 195018
> 
> Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>

Applied to dpdk/master, thanks.
  

Patch

diff --git a/drivers/net/nfp/nfp_nspu.c b/drivers/net/nfp/nfp_nspu.c
index a2819a1..3c8cdad 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -351,12 +351,14 @@ 
 		RTE_LOG(INFO, PMD, "fw file too big: %" PRIu64
 				   " bytes (%" PRIu64 " max)",
 				  (uint64_t)fsize, (uint64_t)size);
+		close(fw_f);
 		return -EINVAL;
 	}
 
 	fw_buf = malloc((size_t)size);
 	if (!fw_buf) {
 		RTE_LOG(INFO, PMD, "malloc failed for fw buffer");
+		close(fw_f);
 		return -ENOMEM;
 	}
 	memset(fw_buf, 0, size);
@@ -367,12 +369,14 @@ 
 				   "Just %" PRIu64 " of %" PRIu64 " bytes read.",
 				   (uint64_t)bytes, (uint64_t)fsize);
 		free(fw_buf);
+		close(fw_f);
 		return -EIO;
 	}
 
 	ret = nspu_command(nspu_desc, NSP_CMD_FW_LOAD, 0, 1, fw_buf, 0, bytes);
 
 	free(fw_buf);
+	close(fw_f);
 
 	return ret;
 }