From 6dece5ac29320c720e2f79ca0f52ebdad7615fc8 Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Wed, 24 Aug 2022 00:35:43 +0200 Subject: sharpd: Fix memory leak in release-locator-chunk Running the `zebra_seg6local_route` topotest with `--valgrind-memleaks` gives several memory leak errors. This is due to the way SRv6 chunks are released: when the user executes the CLI command `sharp srv6-manager release-locator-chunk` to release the chunks of an SRv6 locator, the `list_delete()` function is called to delete the chunks list (`loc->chunks`), but the memory allocated for the chunks is not freed. This patch defines a new callback `sharp_srv6_locator_chunk_free()`. This callback takes care of freeing the memory allocated for a given chunk. When `list_delete()` is called to remove the chunk list `loc->chunks`, it automatically calls `sharp_srv6_locator_chunk_free()` on each element of the list to free the allocated memory before deleting the list. Signed-off-by: Carmine Scarpitta --- sharpd/sharp_vty.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sharpd') diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index b3ac8949e..cfde0749b 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -924,6 +924,11 @@ DEFPY (import_te, return CMD_SUCCESS; } +static void sharp_srv6_locator_chunk_free(struct prefix_ipv6 *chunk) +{ + prefix_ipv6_free((struct prefix_ipv6 **)&chunk); +} + DEFPY (sharp_srv6_manager_get_locator_chunk, sharp_srv6_manager_get_locator_chunk_cmd, "sharp srv6-manager get-locator-chunk NAME$locator_name", @@ -947,6 +952,8 @@ DEFPY (sharp_srv6_manager_get_locator_chunk, loc = XCALLOC(MTYPE_SRV6_LOCATOR, sizeof(struct sharp_srv6_locator)); loc->chunks = list_new(); + loc->chunks->del = + (void (*)(void *))sharp_srv6_locator_chunk_free; snprintf(loc->name, SRV6_LOCNAME_SIZE, "%s", locator_name); listnode_add(sg.srv6_locators, loc); } -- cgit v1.2.3