Patch from: https://github.com/xdp-project/xdp-tools/commit/cae9c91353cd3ed51753168203ed101905b9ac9e From cae9c91353cd3ed51753168203ed101905b9ac9e Mon Sep 17 00:00:00 2001 From: Ric Li Date: Tue, 21 Nov 2023 15:36:57 +0800 Subject: [PATCH] libxdp: Fix xdp prog memory leak in xsk_setup_xdp_prog In the xsk_setup_xdp_prog function, the xsk structure temporarily takes ownership of an xdp_prog and stores it in ctx->xdp_prog. However, the allocated memory is not freed in xsk_destroy_xsk_struct, leading to a memory leak. This commit addresses the issue by adding a call to xdp_program_close to properly release the allocated xdp_prog memory. Signed-off-by: Ric Li --- lib/libxdp/xsk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/libxdp/xsk.c b/lib/libxdp/xsk.c index a854f771..b3527fb6 100644 --- a/lib/libxdp/xsk.c +++ b/lib/libxdp/xsk.c @@ -978,6 +978,7 @@ static struct xsk_ctx *xsk_create_ctx(struct xsk_socket *xsk, static void xsk_destroy_xsk_struct(struct xsk_socket *xsk) { + xdp_program__close(xsk->ctx->xdp_prog); free(xsk->ctx); free(xsk); }