Fix memory leaks found in policer code. 47/7947/4
authorChaoyu Jin <chjin@cisco.com>
Tue, 8 Aug 2017 20:36:23 +0000 (13:36 -0700)
committerNeale Ranns <nranns@cisco.com>
Thu, 10 Aug 2017 21:41:23 +0000 (21:41 +0000)
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>
src/vnet/policer/policer.c

index cd754e2..5a7b771 100644 (file)
@@ -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)
 {