Skip to content

Commit

Permalink
Fixed additional memory leaks in libnl interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jauge-technica committed Aug 3, 2023
1 parent 3a5a1f4 commit a41333f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/linux_daemon/dbus_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
*******************************************************************************/

#pragma GCC diagnostic ignored "-Wstack-usage="

#include "gdbus-mkad-generated.h"
#include "mka_private.h"
#include "mka_types.h"
Expand Down
11 changes: 6 additions & 5 deletions src/linux_daemon/mka_phy_driver_libnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,18 +569,16 @@ static int macsec_drv_create_transmit_sc(
#endif

err = rtnl_link_add(my_libnl_status->nl_sk, link, NLM_F_CREATE);
rtnl_link_put(link);
if (err == -NLE_BUSY) {
MKA_LOG_ERROR("link already exists! Please remove the existing macsec interface before launcing mkad. You may use \"ip link delete\".");
return MKA_NOT_OK;
} else if (err < 0) {
rtnl_link_put(link);
MKA_LOG_ERROR("couldn't create link: err %d", err);
MKA_LOG_ERROR("Is your kernel Macsec capable? Check for the CONFIG_MACSEC configuration flag or the macsec module.");
return MKA_NOT_OK;
}

rtnl_link_put(link);

nl_cache_refill(my_libnl_status->nl_sk, my_libnl_status->link_cache);
link = lookup_sc(my_libnl_status->link_cache, my_libnl_status->parent_ifi, sci, cipher_suite);
if (!link) {
Expand Down Expand Up @@ -723,11 +721,12 @@ t_MKA_result MKA_PHY_UpdateSecY(t_MKA_bus bus, t_MKA_SECY_config const * config,
rtnl_link_unset_flags(change, IFF_UP);

err = rtnl_link_change(my_libnl_status->nl_sk, change, change, 0);
if (err < 0)
return err;

rtnl_link_put(change);

if (err < 0)
return err;

my_libnl_status->controlled_port_enabled = config->controlled_port_enabled;
}

Expand Down Expand Up @@ -1044,6 +1043,7 @@ t_MKA_result MKA_PHY_DeleteTxSA(t_MKA_bus bus, uint8_t an)
MKA_LOG_ERROR("%s: failed to communicate: %d (%s)",
__func__, ret, nl_geterror(-ret));

nlmsg_free(msg);
// Now delete the disabled SA
msg = msg_prepare(bus, MACSEC_CMD_DEL_TXSA, my_libnl_status->ifi);
if (!msg) {
Expand Down Expand Up @@ -1248,6 +1248,7 @@ t_MKA_result MKA_PHY_DeleteRxSA(t_MKA_bus bus, uint8_t an)
MKA_LOG_ERROR("%s: failed to communicate: %d (%s)",
__func__, ret, nl_geterror(-ret));

nlmsg_free(msg);

// Now delete the disabled SA
msg = msg_prepare(bus, MACSEC_CMD_DEL_RXSA, my_libnl_status->ifi);
Expand Down

0 comments on commit a41333f

Please sign in to comment.