[7/7] pipeline: fix instruction config free

Message ID 20201006203755.90779-7-cristian.dumitrescu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [1/7] pipeline: fix memory leak issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Cristian Dumitrescu Oct. 6, 2020, 8:37 p.m. UTC
  Fixes: a1711f948d ("pipeline: add SWX Rx and extract instructions")
Coverity issue: 362901

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/librte_pipeline/rte_swx_pipeline.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
  

Patch

diff --git a/lib/librte_pipeline/rte_swx_pipeline.c b/lib/librte_pipeline/rte_swx_pipeline.c
index a4d072d6d..d5b4a1cc6 100644
--- a/lib/librte_pipeline/rte_swx_pipeline.c
+++ b/lib/librte_pipeline/rte_swx_pipeline.c
@@ -5932,7 +5932,6 @@  instruction_config(struct rte_swx_pipeline *p,
 {
 	struct instruction *instr = NULL;
 	struct instruction_data *data = NULL;
-	char *string = NULL;
 	int err = 0;
 	uint32_t i;
 
@@ -5955,15 +5954,17 @@  instruction_config(struct rte_swx_pipeline *p,
 	}
 
 	for (i = 0; i < n_instructions; i++) {
-		string = strdup(instructions[i]);
+		char *string = strdup(instructions[i]);
 		if (!string) {
 			err = ENOMEM;
 			goto error;
 		}
 
 		err = instr_translate(p, a, string, &instr[i], &data[i]);
-		if (err)
+		if (err) {
+			free(string);
 			goto error;
+		}
 
 		free(string);
 	}
@@ -5982,8 +5983,6 @@  instruction_config(struct rte_swx_pipeline *p,
 	if (err)
 		goto error;
 
-	free(data);
-
 	if (a) {
 		a->instructions = instr;
 		a->n_instructions = n_instructions;
@@ -5992,10 +5991,10 @@  instruction_config(struct rte_swx_pipeline *p,
 		p->n_instructions = n_instructions;
 	}
 
+	free(data);
 	return 0;
 
 error:
-	free(string);
 	free(data);
 	free(instr);
 	return err;