opticsmon: Fix error path free of struct optics in ethtool_nl_get_optics()

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: c34adb9cab ("opticsmon: Introduce opticsmon tool")
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Niklas Schnelle
2026-04-16 11:46:59 +02:00
committed by Jan Höppner
parent 1f339a9e7e
commit 6847b6a8cf

View File

@@ -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;
}