From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <fanzhan2@ecsmtp.ir.intel.com>
Received: from mga14.intel.com (mga14.intel.com [192.55.52.115])
 by dpdk.org (Postfix) with ESMTP id CA8A85685
 for <dev@dpdk.org>; Fri, 27 Nov 2015 17:15:00 +0100 (CET)
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by fmsmga103.fm.intel.com with ESMTP; 27 Nov 2015 08:14:36 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.20,352,1444719600"; d="scan'208";a="608161278"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by FMSMGA003.fm.intel.com with ESMTP; 27 Nov 2015 08:14:35 -0800
Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com
 [10.237.217.46])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 tARFqeGS008581; Fri, 27 Nov 2015 15:52:40 GMT
Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1])
 by sivswdev02.ir.intel.com with ESMTP id tARFqejn019320;
 Fri, 27 Nov 2015 15:52:40 GMT
Received: (from fanzhan2@localhost)
 by sivswdev02.ir.intel.com with  id tARFqefE019316;
 Fri, 27 Nov 2015 15:52:40 GMT
From: Fan Zhang <roy.fan.zhang@intel.com>
To: cristian.dumitrescu@intel.com
Date: Fri, 27 Nov 2015 15:52:38 +0000
Message-Id: <1448639558-19285-1-git-send-email-roy.fan.zhang@intel.com>
X-Mailer: git-send-email 1.7.4.1
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] example/ip_pipeline: fix resource leak problem.
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 27 Nov 2015 16:15:01 -0000

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