vlib: avoid confusion when parsing plugins section 49/42649/6
authorNicolas PLANEL <[email protected]>
Thu, 3 Apr 2025 08:54:15 +0000 (10:54 +0200)
committerDamjan Marion <[email protected]>
Sun, 13 Apr 2025 19:05:45 +0000 (19:05 +0000)
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 <[email protected]>
src/vlib/unix/plugin.c

index 77e4633..c784c5b 100644 (file)
@@ -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;