stats: fix the memory leak in stat_client.c 30/37730/3
authorAndrew Yourtchenko <ayourtch@gmail.com>
Mon, 28 Nov 2022 17:56:16 +0000 (17:56 +0000)
committerOle Tr�an <otroan@employees.org>
Tue, 29 Nov 2022 13:48:45 +0000 (13:48 +0000)
The issue can be reproduced by running "vpp_get_stats tightpoll"

The root cause is that the control flow discards the "result" struct
being prepared, along with pointer its allocated name.
This results in a memory leak.

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

index 2e8e1fa..5bb6e9f 100644 (file)
@@ -287,6 +287,8 @@ copy_data (vlib_stats_entry_t *ep, u32 index2, char *name,
       {
        vlib_stats_entry_t *ep2;
        ep2 = vec_elt_at_index (sm->directory_vector, ep->index1);
+       /* We do not intend to return the "result", avoid a leak */
+       free (result.name);
        return copy_data (ep2, ep->index2, ep->name, sm);
       }