api: fix memory leak in vl_api_cli_inband_t_handler 69/31369/4
authorAndrew Yourtchenko <ayourtch@gmail.com>
Mon, 22 Feb 2021 01:01:43 +0000 (01:01 +0000)
committerFlorin Coras <florin.coras@gmail.com>
Mon, 22 Feb 2021 22:28:15 +0000 (22:28 +0000)
I noticed the memory leak while sending a lot of cli_inband APIs:

DBGvpp# memory-trace on main-heap

... send a lot of API cli_inband ...

DBGvpp# show memory main-heap
Thread 0 vpp_main
  base 0x7f85c8302000, size 1g, locked, unmap-on-destroy, name 'main heap'
    page stats: page-size 4K, total 262144, mapped 33129, not-mapped 229015
      numa 0: 33129 pages, 129.41m bytes
    total: 1023.99M, used: 125.78M, free: 898.22M, trimmable: 897.59M

  Bytes    Count     Sample   Traceback
  9751632   145034 0x7f85d01696e8 clib_mem_alloc_aligned_at_offset + 0x80
                                  vec_resize_allocate_memory + 0xa8
                                  _vec_resize_inline + 0x240
                                  va_unformat + 0xe4
                                  unformat + 0x159
                                  vlib_cli_dispatch_sub_commands + 0x11e
                                  vlib_cli_input + 0x8f
                                  vl_api_cli_inband_t_handler + 0xd9
                                  vl_msg_api_handler_with_vm_node + 0x488
                                  void_mem_api_handle_msg_i + 0x6f
                                  vl_mem_api_handle_msg_main + 0x38
                                  vl_api_clnt_process + 0x28d
  9723904   145034 0x7f85cd677238 clib_mem_alloc_aligned_at_offset + 0x80
                                  vec_resize_allocate_memory + 0xa8
                                  _vec_resize_inline + 0x240
                                  unformat_init_string + 0x10d
                                  vl_api_cli_inband_t_handler + 0xc1
                                  vl_msg_api_handler_with_vm_node + 0x488
                                  void_mem_api_handle_msg_i + 0x6f
                                  vl_mem_api_handle_msg_main + 0x38
                                  vl_api_clnt_process + 0x28d
                                  vlib_process_bootstrap + 0x5d
                                  0x7f8608b0e038
290077 total traced objects

Solution: free the input data structure.

Type: fix
Change-Id: I42de5572e8760237e793a53c1a94bce65a4ac5fa
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/vpp/api/api.c

index 6007b72..cd5bc72 100644 (file)
@@ -225,6 +225,7 @@ vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
   unformat_init_string (&input, (char *) cmd_vec,
                        vl_api_string_len (&mp->cmd));
   rv = vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
+  unformat_free (&input);
 
 error:
   /* *INDENT-OFF* */