DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] examples/pipeline: fix resource release in table update
Date: Tue, 13 Oct 2020 19:40:36 +0100	[thread overview]
Message-ID: <20201013184036.47101-1-cristian.dumitrescu@intel.com> (raw)

Fix the resource release sequence in table update.

Fixes: 5074e1d551 ("examples/pipeline: add configuration commands")
Coverity issues: 362882, 363041, 363044, 363047

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 76a58ee28..5800cc98e 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -866,7 +866,7 @@ cmd_pipeline_table_update(char **tokens,
 	}
 
 	/* Add. */
-	if (file_add) {
+	if (file_add)
 		for (line_id = 1; ; line_id++) {
 			struct rte_swx_table_entry *entry;
 
@@ -893,11 +893,9 @@ cmd_pipeline_table_update(char **tokens,
 			}
 		}
 
-		fclose(file_add);
-	}
 
 	/* Delete. */
-	if (file_delete) {
+	if (file_delete)
 		for (line_id = 1; ; line_id++) {
 			struct rte_swx_table_entry *entry;
 
@@ -924,11 +922,8 @@ cmd_pipeline_table_update(char **tokens,
 			}
 		}
 
-		fclose(file_delete);
-	}
-
 	/* Default. */
-	if (file_default) {
+	if (file_default)
 		for (line_id = 1; ; line_id++) {
 			struct rte_swx_table_entry *entry;
 
@@ -955,19 +950,22 @@ cmd_pipeline_table_update(char **tokens,
 			}
 		}
 
-		fclose(file_default);
-	}
-
 	status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
 	if (status) {
 		snprintf(out, out_size, "Commit failed.");
 		goto error;
 	}
 
-	free(line);
 
 	rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
 
+	free(line);
+	if (file_add)
+		fclose(file_add);
+	if (file_delete)
+		fclose(file_delete);
+	if (file_default)
+		fclose(file_default);
 	return;
 
 error:
-- 
2.17.1


             reply	other threads:[~2020-10-13 18:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13 18:40 Cristian Dumitrescu [this message]
2020-10-19  7:10 ` David Marchand

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=20201013184036.47101-1-cristian.dumitrescu@intel.com \
    --to=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).