[dpdk-dev,v1] lib: fix coverity issues in distributor allocation

Message ID 1491273761-112722-1-git-send-email-david.hunt@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

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

Commit Message

Hunt, David April 4, 2017, 2:42 a.m. UTC
  Coverity issue 143258: not freeing distributor instance
Coverity issue 143254: not checking return code from malloc

Fixes: 775003ad2f96 ("distributor: add new burst-capable library")

Signed-off-by: David Hunt <david.hunt@intel.com>
---
 lib/librte_distributor/rte_distributor.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Thomas Monjalon April 4, 2017, 12:58 p.m. UTC | #1
2017-04-04 03:42, David Hunt:
> Coverity issue 143258: not freeing distributor instance
> Coverity issue 143254: not checking return code from malloc
> 
> Fixes: 775003ad2f96 ("distributor: add new burst-capable library")
> 
> Signed-off-by: David Hunt <david.hunt@intel.com>

Applied with this title:
	distributor: fix creation error checks
Thanks
  

Patch

diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
index 06df13d..4725904 100644
--- a/lib/librte_distributor/rte_distributor.c
+++ b/lib/librte_distributor/rte_distributor.c
@@ -621,9 +621,14 @@  rte_distributor_create_v1705(const char *name,
 
 	if (alg_type == RTE_DIST_ALG_SINGLE) {
 		d = malloc(sizeof(struct rte_distributor));
+		if (d == NULL) {
+			rte_errno = ENOMEM;
+			return NULL;
+		}
 		d->d_v20 = rte_distributor_create_v20(name,
 				socket_id, num_workers);
 		if (d->d_v20 == NULL) {
+			free(d);
 			/* rte_errno will have been set */
 			return NULL;
 		}