DPDK patches and discussions
 help / color / mirror / Atom feed
From: Fan Zhang <roy.fan.zhang@intel.com>
To: cristian.dumitrescu@intel.com
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] example/ip_pipeline: fix resource leak problem.
Date: Fri, 27 Nov 2015 15:52:38 +0000	[thread overview]
Message-ID: <1448639558-19285-1-git-send-email-roy.fan.zhang@intel.com> (raw)

This patch fix the following Coverity issue:

Coverity issue: 120147
Fixes: 7122d30131ad ("examples/ip_pipeline: rework flow classification
pipeline")

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
---
 .../pipeline/pipeline_flow_classification_be.c     | 31 +++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c
index e22f96f..75a2a6b 100644
--- a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c
+++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c
@@ -141,12 +141,12 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 		/* n_flows */
 		if (strcmp(arg_name, "n_flows") == 0) {
 			if (n_flows_present)
-				return -1;
+				goto error_parse;
 			n_flows_present = 1;
 
 			p->n_flows = atoi(arg_value);
 			if (p->n_flows == 0)
-				return -1;
+				goto error_parse;
 
 			continue;
 		}
@@ -154,7 +154,8 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 		/* key_offset */
 		if (strcmp(arg_name, "key_offset") == 0) {
 			if (key_offset_present)
-				return -1;
+				goto error_parse;
+
 			key_offset_present = 1;
 
 			p->key_offset = atoi(arg_value);
@@ -165,14 +166,14 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 		/* key_size */
 		if (strcmp(arg_name, "key_size") == 0) {
 			if (key_size_present)
-				return -1;
+				goto error_parse;
 			key_size_present = 1;
 
 			p->key_size = atoi(arg_value);
 			if ((p->key_size == 0) ||
 				(p->key_size > PIPELINE_FC_FLOW_KEY_MAX_SIZE) ||
 				(p->key_size % 8))
-				return -1;
+				goto error_parse;
 
 			continue;
 		}
@@ -180,11 +181,11 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 		/* key_mask */
 		if (strcmp(arg_name, "key_mask") == 0) {
 			if (key_mask_present)
-				return -1;
+				goto error_parse;
 
 			key_mask_str = strdup(arg_value);
 			if (key_mask_str == NULL)
-				return -1;
+				goto error_parse;
 
 			key_mask_present = 1;
 
@@ -194,7 +195,7 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 		/* hash_offset */
 		if (strcmp(arg_name, "hash_offset") == 0) {
 			if (hash_offset_present)
-				return -1;
+				goto error_parse;
 			hash_offset_present = 1;
 
 			p->hash_offset = atoi(arg_value);
@@ -210,23 +211,29 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
 	if ((n_flows_present == 0) ||
 		(key_offset_present == 0) ||
 		(key_size_present == 0))
-		return -1;
+		goto error_parse;
 
 	if (key_mask_present) {
 		p->key_mask = rte_malloc(NULL, p->key_size, 0);
 		if (p->key_mask == NULL)
-			return -1;
+			goto error_parse;
 
 		if (parse_hex_string(key_mask_str, p->key_mask, &p->key_size)
 			!= 0) {
-			free(p->key_mask);
-			return -1;
+			goto error_parse;
 		}
 
 		free(key_mask_str);
 	}
 
 	return 0;
+
+error_parse:
+	if (key_mask_str != NULL)
+		free(key_mask_str);
+	if (p->key_mask != NULL)
+		free(p->key_mask);
+	return -1;
 }
 
 static void *pipeline_fc_init(struct pipeline_params *params,
-- 
2.5.0

             reply	other threads:[~2015-11-27 16:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-27 15:52 Fan Zhang [this message]
2015-12-07  0:15 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448639558-19285-1-git-send-email-roy.fan.zhang@intel.com \
    --to=roy.fan.zhang@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).