[dpdk-dev,v1] app: fix Coverity issues

Message ID 1466430578-1224-1-git-send-email-remy.horton@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Remy Horton June 20, 2016, 1:49 p.m. UTC
  Fixes memory leaks detected by Coverity. These are due to ephemeral
memory allocations not being freed when errors occur.

Coverity issue 127348: Resource leak
Coverity issue 127349: Resource leak

Fixes: e2aae1c1ced9 ("ethdev: remove name from extended statistic fetch")

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 app/test-pmd/config.c          | 3 +++
 examples/l2fwd-keepalive/shm.c | 2 ++
 2 files changed, 5 insertions(+)
  

Comments

Thomas Monjalon June 20, 2016, 1:56 p.m. UTC | #1
2016-06-20 14:49, Remy Horton:
> Fixes memory leaks detected by Coverity. These are due to ephemeral
> memory allocations not being freed when errors occur.
> 
> Coverity issue 127348: Resource leak
> Coverity issue 127349: Resource leak
> 
> Fixes: e2aae1c1ced9 ("ethdev: remove name from extended statistic fetch")
> 
> Signed-off-by: Remy Horton <remy.horton@intel.com>
> ---
>  app/test-pmd/config.c          | 3 +++
>  examples/l2fwd-keepalive/shm.c | 2 ++

It looks to be 2 patches: one for xstats and the other for keepalive.
  
Remy Horton June 20, 2016, 2:50 p.m. UTC | #2
On 20/06/2016 14:56, Thomas Monjalon wrote:
[..]
> It looks to be 2 patches: one for xstats and the other for keepalive.
>

Ok, will seperate. I combined them since they were the same small fix in 
multiple places.
  
Remy Horton June 20, 2016, 3:23 p.m. UTC | #3
Fixes memory leaks detected by Coverity. These are due to ephemeral
memory allocations not being freed when errors occur.

--
v2 changes:
* Split patch into two

Remy Horton (2):
  app/test-pmd: fix Coverity issues
  examples/l2fwd-keepalive: fix Coverity issues

 app/test-pmd/config.c          | 3 +++
 examples/l2fwd-keepalive/shm.c | 2 ++
 2 files changed, 5 insertions(+)
  
Thomas Monjalon June 21, 2016, 1:58 p.m. UTC | #4
> Remy Horton (2):
>   app/test-pmd: fix Coverity issues
>   examples/l2fwd-keepalive: fix Coverity issues

Applied with titles reworded as suggested by Pablo, thanks
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 10f0a36..cb71c09 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -281,6 +281,7 @@  nic_xstats_display(portid_t port_id)
 	if (cnt_xstats != rte_eth_xstats_get_names(
 			port_id, xstats_names, cnt_xstats)) {
 		printf("Error: Cannot get xstats lookup\n");
+		free(xstats_names);
 		return;
 	}
 
@@ -293,6 +294,8 @@  nic_xstats_display(portid_t port_id)
 	}
 	if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
 		printf("Error: Unable to get xstats\n");
+		free(xstats_names);
+		free(xstats);
 		return;
 	}
 
diff --git a/examples/l2fwd-keepalive/shm.c b/examples/l2fwd-keepalive/shm.c
index 66fc433..177aa5b 100644
--- a/examples/l2fwd-keepalive/shm.c
+++ b/examples/l2fwd-keepalive/shm.c
@@ -80,6 +80,8 @@  struct rte_keepalive_shm *rte_keepalive_shm_create(void)
 				RTE_LOG(INFO, EAL,
 					"Failed to setup SHM semaphore (%s)\n",
 					strerror(errno));
+				munmap(ka_shm,
+					sizeof(struct rte_keepalive_shm));
 				return NULL;
 			}