[v2,15/16] examples/qos_sched: fix memory leak when parse args

Message ID 20231110100117.8350-16-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series verify strdup return value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen Nov. 10, 2023, 10:01 a.m. UTC
  Should free the memory which allocated by strdup().

Fixes: 035b6a4f4bba ("examples/qos_sched: fix out-of-bounds option parsing")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/qos_sched/args.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index e97273152a..8d61d3e454 100644
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -103,8 +103,10 @@  app_parse_opt_vals(const char *conf_str, char separator, uint32_t n_vals, uint32
 
 	n_tokens = rte_strsplit(string, strnlen(string, 32), tokens, n_vals, separator);
 
-	if (n_tokens > MAX_OPT_VALUES)
+	if (n_tokens > MAX_OPT_VALUES) {
+		free(string);
 		return -1;
+	}
 
 	for (i = 0; i < n_tokens; i++)
 		opt_vals[i] = (uint32_t)atol(tokens[i]);