From 6946731314fd04c499e576d0e133879f3e9c2edd Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Sat, 29 Oct 2022 17:04:35 +0200 Subject: lib, bgpd: Enhance `srv6_locator_chunk_free()` API A programmer can use the `srv6_locator_chunk_free()` function to free the memory allocated for a `struct srv6_locator_chunk`. The programmer invokes `srv6_locator_chunk_free()` by passing a single pointer to the `struct srv6_locator_chunk` to be freed. `srv6_locator_chunk_free()` uses `XFREE()` to free the memory. It is the responsibility of the programmer to set the `struct srv6_locator_chunk` pointer to NULL after freeing memory with `srv6_locator_chunk_free()`. This commit modifies the `srv6_locator_chunk_free()` function to take a double pointer instead of a single pointer. In this way, setting the `struct srv6_locator_chunk` pointer to NULL is no longer the programmer's responsibility but is the responsibility of `srv6_locator_chunk_free()`. This prevents programmers from making mistakes such as forgetting to set the pointer to NULL after invoking `srv6_locator_chunk_free()`. Signed-off-by: Carmine Scarpitta --- lib/srv6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/srv6.c') diff --git a/lib/srv6.c b/lib/srv6.c index 306d92ae30..a8ec6f2b71 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -157,9 +157,9 @@ void srv6_locator_free(struct srv6_locator *locator) } } -void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk) +void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk) { - XFREE(MTYPE_SRV6_LOCATOR_CHUNK, chunk); + XFREE(MTYPE_SRV6_LOCATOR_CHUNK, *chunk); } json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk) -- cgit v1.2.3