From 6847b6a8cf60510a63c5e4f32ca429ca9f5d24a7 Mon Sep 17 00:00:00 2001 From: Niklas Schnelle Date: Thu, 16 Apr 2026 11:46:59 +0200 Subject: [PATCH] opticsmon: Fix error path free of struct optics in ethtool_nl_get_optics() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When ethtool_nl_get_optics() fails after ethtool_nl_cb() has allocated oi->raw this memory would leak because only the struct optics* itself was freed. Fix this by using optics_free() and relying on free(oi->raw) being a no-op for NULL pointers in combination with using util_zalloc() to handle errors both before and after oi->raw was allocated. Fixes: c34adb9cabee ("opticsmon: Introduce opticsmon tool") Reviewed-by: Jan Höppner Signed-off-by: Niklas Schnelle Signed-off-by: Jan Höppner --- opticsmon/ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opticsmon/ethtool.c b/opticsmon/ethtool.c index 103644a1..a448eb25 100644 --- a/opticsmon/ethtool.c +++ b/opticsmon/ethtool.c @@ -272,7 +272,7 @@ int ethtool_nl_get_optics(struct ethtool_nl_ctx *ctx, const char *netdev, struct return rc; out_err_free_oi: - free(*oi); + optics_free(*oi); *oi = NULL; return rc; }