aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2023-03-23 22:09:51 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2023-04-17 14:04:06 +0000
commit22ca0d03dbc82c3eb9ccd995aaef3ae924f67b97 (patch)
tree077fdcdfc3bbe0e87b25f32c42b7fb563aabb923
parent003330c55a0e55cfabf2384dc310bd1c0e0254b9 (diff)
stats: check if stats vector entry is empty
When a stats entry is removed it is marked empty. The stats client did not check for that and returned an empty string. This resulted in blank lines in vpp_get_stats. Fix by returning null instead and checking value. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I08a39ba3ef4421bf275747a6300f97fe36791b50
-rw-r--r--src/vpp-api/client/stat_client.c5
-rw-r--r--src/vpp/app/vpp_get_stats.c2
2 files changed, 7 insertions, 0 deletions
diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c
index 01ed7c7e137..1c31ea0cb23 100644
--- a/src/vpp-api/client/stat_client.c
+++ b/src/vpp-api/client/stat_client.c
@@ -512,6 +512,11 @@ stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm)
return 0;
vec = get_stat_vector_r (sm);
ep = vec_elt_at_index (vec, index);
+ if (ep->type == STAT_DIR_TYPE_EMPTY)
+ {
+ stat_segment_access_end (&sa, sm);
+ return 0;
+ }
if (!stat_segment_access_end (&sa, sm))
return 0;
return strdup (ep->name);
diff --git a/src/vpp/app/vpp_get_stats.c b/src/vpp/app/vpp_get_stats.c
index a37dfca57a8..54d36abcbf2 100644
--- a/src/vpp/app/vpp_get_stats.c
+++ b/src/vpp/app/vpp_get_stats.c
@@ -179,6 +179,8 @@ reconnect:
for (i = 0; i < vec_len (dir); i++)
{
char *n = stat_segment_index_to_name (dir[i]);
+ if (!n)
+ continue;
printf ("%s\n", n);
free (n);
}