From 9efdde87fac7f9f0ee73ec5d6764a3e9b9efeb43 Mon Sep 17 00:00:00 2001 From: Nicolas PLANEL Date: Thu, 3 Apr 2025 10:54:15 +0200 Subject: [PATCH] vlib: avoid confusion when parsing plugins section config_one_plugin steal the vector allocated by unformat() and memory leak in the error path of config_one_plugin call vec_dup() and vec_free() when it's needed Type: fix Change-Id: I2407e0981e9628c40908cdd26683b98ae27c2159 Signed-off-by: Nicolas PLANEL --- src/vlib/unix/plugin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c index 77e4633e14a..c784c5b44ad 100644 --- a/src/vlib/unix/plugin.c +++ b/src/vlib/unix/plugin.c @@ -748,11 +748,11 @@ config_one_plugin (vlib_main_t * vm, char *name, unformat_input_t * input) } vec_add2 (pm->configs, pc, 1); - hash_set_mem (pm->config_index_by_name, name, pc - pm->configs); pc->is_enabled = is_enable; pc->is_disabled = is_disable; pc->skip_version_check = skip_version_check; - pc->name = name; + pc->name = vec_dup (name); + hash_set_mem (pm->config_index_by_name, pc->name, pc - pm->configs); done: return error; @@ -816,6 +816,7 @@ done: unformat_vlib_cli_sub_input, &sub_input)) { error = config_one_plugin (vm, (char *) s, &sub_input); + vec_free (s); unformat_free (&sub_input); if (error) goto done2; -- 2.16.6