aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/policer
diff options
context:
space:
mode:
authorChaoyu Jin <chjin@cisco.com>2017-08-08 13:36:23 -0700
committerNeale Ranns <nranns@cisco.com>2017-08-10 21:41:23 +0000
commit913b87306642a1c2d59431e4d0639c7a8399808f (patch)
tree8c61a0021a900fc5a58116ef278ea7164405e09f /src/vnet/policer
parent1b1dfb110add43ec85d46f160b912fc1b7dd9b03 (diff)
Fix memory leaks found in policer code.
2nd commit is to fix style failures. 3rd commit is to remove unneccesary change based on review comment. Change-Id: I4d54d25c27e037b9d0438f8af416cf113763dc6d Signed-off-by: Chaoyu Jin <chjin@cisco.com>
Diffstat (limited to 'src/vnet/policer')
-rw-r--r--src/vnet/policer/policer.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c
index cd754e29..5a7b7711 100644
--- a/src/vnet/policer/policer.c
+++ b/src/vnet/policer/policer.c
@@ -33,13 +33,26 @@ policer_add_del (vlib_main_t * vm,
if (is_add == 0)
{
+ /* free policer config and template */
if (p == 0)
{
vec_free (name);
return clib_error_return (0, "No such policer configuration");
}
+ pool_put_index (pm->configs, p[0]);
+ pool_put_index (pm->policer_templates, p[0]);
hash_unset_mem (pm->policer_config_by_name, name);
+
+ /* free policer */
+ p = hash_get_mem (pm->policer_index_by_name, name);
+ if (p == 0)
+ {
+ vec_free (name);
+ return clib_error_return (0, "No such policer");
+ }
+ pool_put_index (pm->policers, p[0]);
hash_unset_mem (pm->policer_index_by_name, name);
+
vec_free (name);
return 0;
}
@@ -500,6 +513,27 @@ VLIB_CLI_COMMAND (show_policer_command, static) = {
};
/* *INDENT-ON* */
+static clib_error_t *
+show_policer_pools_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ vnet_policer_main_t *pm = &vnet_policer_main;
+
+ vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d",
+ pool_elts (pm->configs),
+ pool_elts (pm->policer_templates),
+ pool_elts (pm->policers));
+ return 0;
+}
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_policer_pools_command, static) = {
+ .path = "show policer pools",
+ .short_help = "show policer pools",
+ .function = show_policer_pools_command_fn,
+};
+/* *INDENT-ON* */
+
clib_error_t *
policer_init (vlib_main_t * vm)
{