aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-06-12 16:50:38 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-06-12 21:58:33 +0000
commitf35a07273f252b98f65126c747bfb1eb435f0ace (patch)
treeddd1f99c11d539bfb9d20fa5311f27dcc344ed3e /src
parent0f87dfeec6c38035e6fbcfdd9a33c60c51f9514e (diff)
infra: fix minor memory leak in "api trace..."
Build api trace message print fns into the built-in copy of api_format.c Optimize memory allocator behavior when the api trace wraps. Type: Fix Change-Id: If799d8784a459f981fc9ee3a3ca03d3f63b2bcd0 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src')
-rw-r--r--src/vat/api_format.c4
-rw-r--r--src/vlibapi/api_shared.c4
-rwxr-xr-xsrc/vlibmemory/vlib_api_cli.c13
3 files changed, 15 insertions, 6 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index be074bec615..60d66be368d 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -73,7 +73,11 @@
#undef vl_endianfun
/* instantiate all the print functions we know about */
+#if VPP_API_TEST_BUILTIN == 0
#define vl_print(handle, ...)
+#else
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
+#endif
#define vl_printfun
#include <vpp/api/vpe_all_api_h.h>
#undef vl_printfun
diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c
index cee9cd54f5f..77a18c9e73c 100644
--- a/src/vlibapi/api_shared.c
+++ b/src/vlibapi/api_shared.c
@@ -97,7 +97,9 @@ vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg)
old_trace = tp->traces + tp->curindex++;
if (tp->curindex == tp->nitems)
tp->curindex = 0;
- vec_free (*old_trace);
+ /* Reuse the trace record, may save some memory allocator traffic */
+ msg_copy = *old_trace;
+ vec_reset_length (msg_copy);
this_trace = old_trace;
}
diff --git a/src/vlibmemory/vlib_api_cli.c b/src/vlibmemory/vlib_api_cli.c
index 4a86b8d76bb..b5fe151a2c0 100755
--- a/src/vlibmemory/vlib_api_cli.c
+++ b/src/vlibmemory/vlib_api_cli.c
@@ -664,7 +664,8 @@ api_trace_command_fn (vlib_main_t * vm,
u32 nitems = 256 << 10;
api_main_t *am = &api_main;
vl_api_trace_which_t which = VL_API_TRACE_RX;
- u8 *filename;
+ u8 *filename = 0;
+ u8 *chroot_filename = 0;
u32 first = 0;
u32 last = (u32) ~ 0;
FILE *fp;
@@ -685,13 +686,12 @@ api_trace_command_fn (vlib_main_t * vm,
}
else if (unformat (input, "save %s", &filename))
{
- u8 *chroot_filename;
if (strstr ((char *) filename, "..")
|| index ((char *) filename, '/'))
{
vlib_cli_output (vm, "illegal characters in filename '%s'",
filename);
- return 0;
+ goto out;
}
chroot_filename = format (0, "/tmp/%s%c", filename, 0);
@@ -702,7 +702,7 @@ api_trace_command_fn (vlib_main_t * vm,
if (fp == NULL)
{
vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
- return 0;
+ goto out;
}
rv = vl_msg_api_trace_save (am, which, fp);
fclose (fp);
@@ -724,7 +724,7 @@ api_trace_command_fn (vlib_main_t * vm,
vlib_cli_output (vm, "Unknown error while saving: %d", rv);
else
vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
- vec_free (chroot_filename);
+ goto out;
}
else if (unformat (input, "dump %s", &filename))
{
@@ -772,6 +772,9 @@ api_trace_command_fn (vlib_main_t * vm,
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
}
+out:
+ vec_free (filename);
+ vec_free (chroot_filename);
return 0;
}