lldp: fix memory leakage

1. Typo in usage of vnet_hw_interface_add_del_mac_address(),
   which returns 0 when it succeeds instead non zero value.

2. Generated error doesn't clean allocated resources for
   an interface.

3. Returned value from vnet_hw_interface_add_del_mac_address()
   should be erased or reported.

Type: fix
Fixes: 149fd3fbd069a5f7be86e68472578ee7af229cb6

Signed-off-by: Dmitry Vakhrushev <dmitry@netgate.com>
Change-Id: Ia6b28ae70fea127d15eb0102223ff972358766bc
Signed-off-by: Dmitry Vakhrushev <dmitry@netgate.com>
This commit is contained in:
Dmitry Vakhrushev
2020-10-12 13:43:39 +03:00
parent 6b410e6d7c
commit decf51a86a

View File

@ -49,6 +49,7 @@ lldp_cfg_err_t
lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
u8 ** mgmt_ip6, u8 ** mgmt_oid, int enable)
{
clib_error_t *error = 0;
lldp_main_t *lm = &lldp_main;
vnet_main_t *vnm = lm->vnet_main;
ethernet_main_t *em = &ethernet_main;
@ -101,10 +102,14 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
*mgmt_oid = NULL;
}
if (!vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
1 /* is_add */ ))
error =
vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
1 /* is_add */ );
if (error)
{
clib_error_free (error);
lldp_delete_intf (lm, n);
return lldp_internal_error;
}
@ -121,9 +126,14 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
lldp_delete_intf (lm, n);
if (n)
{
vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
0 /* is_add */ );
error =
vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
0 /* is_add */ );
if (error)
{
clib_error_free (error);
}
}
}