From 8fca3f99cf199a73e8ec1e4646b51e04fe011a70 Mon Sep 17 00:00:00 2001 From: Eelco Chaudron Date: Thu, 5 Jun 2025 16:51:25 +0200 Subject: [PATCH] lldp: Fix Coverity warning about resource leak in lldp test. Coverity reported a potential resource leak in the LLDP test code. While this condition should never occur in practice, since the test would crash on out-of-memory, the warning is addressed by ensuring the cleanup function is called on error paths. Acked-by: Aaron Conole Signed-off-by: Eelco Chaudron --- lib/ovs-lldp.c | 23 +++++++++++++---------- tests/test-aa.c | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index 2d13e971e..863a1b644 100644 --- a/lib/ovs-lldp.c +++ b/lib/ovs-lldp.c @@ -971,18 +971,21 @@ lldp_destroy_dummy(struct lldp *lldp) cfg = lldp->lldpd; - LIST_FOR_EACH_SAFE (hw, h_entries, &cfg->g_hardware) { - ovs_list_remove(&hw->h_entries); - free(hw->h_lport.p_lastframe); - free(hw); + if (cfg) { + LIST_FOR_EACH_SAFE (hw, h_entries, &cfg->g_hardware) { + ovs_list_remove(&hw->h_entries); + free(hw->h_lport.p_lastframe); + free(hw); + } + + LIST_FOR_EACH_SAFE (chassis, list, &cfg->g_chassis) { + ovs_list_remove(&chassis->list); + free(chassis); + } + + free(lldp->lldpd); } - LIST_FOR_EACH_SAFE (chassis, list, &cfg->g_chassis) { - ovs_list_remove(&chassis->list); - free(chassis); - } - - free(lldp->lldpd); free(lldp); } diff --git a/tests/test-aa.c b/tests/test-aa.c index 1c0fb2926..ba21d5908 100644 --- a/tests/test-aa.c +++ b/tests/test-aa.c @@ -183,6 +183,7 @@ test_aa_send(void) (lldp->lldpd == NULL) || ovs_list_is_empty(&lldp->lldpd->g_hardware)) { printf("Error: unable to create dummy lldp instance"); + lldp_destroy_dummy(lldp); return 1; }