Skip to content

Commit 932005a

Browse files
spirioudanieldegrasse
authored andcommitted
net: l2: ieee802154: mgmt: fix net_pkt leaks
The ieee802154_radio_send() function does not decrease reference counter of the net_pkt, it's instead done one layer above in ieee802154_send(). This commit updates the mgmt functions using ieee802154_radio_send() to always free the used net_pkt afterward. Signed-off-by: Simon Piriou <spiriou31@gmail.com>
1 parent 28f37e5 commit 932005a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

subsys/net/l2/ieee802154/ieee802154_mgmt.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ static int ieee802154_scan(uint64_t mgmt_request, struct net_if *iface,
178178

179179
/* Active scan sends a beacon request */
180180
if (mgmt_request == NET_REQUEST_IEEE802154_ACTIVE_SCAN) {
181-
net_pkt_ref(pkt);
182-
net_pkt_frag_ref(pkt->buffer);
183-
184181
ret = ieee802154_radio_send(iface, pkt, pkt->buffer);
185182
if (ret) {
186183
NET_ERR("Scan request failed: could not send Beacon "
@@ -565,7 +562,6 @@ static int ieee802154_associate(uint64_t mgmt_request, struct net_if *iface,
565562
* existing PAN.
566563
*/
567564
if (ieee802154_radio_send(iface, pkt, pkt->buffer)) {
568-
net_pkt_unref(pkt);
569565
ret = -EIO;
570566
k_sem_give(&ctx->scan_ctx_lock);
571567
NET_ERR("Could not associate: cannot send association request");
@@ -625,6 +621,10 @@ static int ieee802154_associate(uint64_t mgmt_request, struct net_if *iface,
625621
k_sem_give(&ctx->ctx_lock);
626622
}
627623

624+
if (pkt) {
625+
net_pkt_unref(pkt);
626+
}
627+
628628
return ret;
629629
}
630630

@@ -634,6 +634,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_ASSOCIATE,
634634
static int ieee802154_disassociate(uint64_t mgmt_request, struct net_if *iface,
635635
void *data, size_t len)
636636
{
637+
int ret;
637638
struct ieee802154_context *ctx = net_if_l2_data(iface);
638639
struct ieee802154_frame_params params = {0};
639640
struct ieee802154_command *cmd;
@@ -690,8 +691,9 @@ static int ieee802154_disassociate(uint64_t mgmt_request, struct net_if *iface,
690691
ieee802154_mac_cmd_finalize(
691692
pkt, IEEE802154_CFI_DISASSOCIATION_NOTIFICATION);
692693

693-
if (ieee802154_radio_send(iface, pkt, pkt->buffer)) {
694-
net_pkt_unref(pkt);
694+
ret = ieee802154_radio_send(iface, pkt, pkt->buffer);
695+
net_pkt_unref(pkt);
696+
if (ret) {
695697
NET_ERR("Could not disassociate: cannot send disassociation notification");
696698
return -EIO;
697699
}

0 commit comments

Comments
 (0)