diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c index f7ced0bd1..332385ba1 100644 --- a/nimble/host/mesh/src/access.c +++ b/nimble/host/mesh/src/access.c @@ -165,10 +165,12 @@ static int publish_retransmit(struct bt_mesh_model *mod) .xmit = bt_mesh_net_transmit_get(), .friend_cred = pub->cred, }; + int err; key = bt_mesh_app_key_find(pub->key); if (!key) { - return -EADDRNOTAVAIL; + err = -EADDRNOTAVAIL; + goto done; } tx.sub = bt_mesh_subnet_get(key->net_idx); @@ -181,7 +183,11 @@ static int publish_retransmit(struct bt_mesh_model *mod) pub->count--; - return bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod); + err = bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod); + +done: + os_mbuf_free_chain(sdu); + return err; } static void mod_publish(struct ble_npl_event *work) @@ -671,10 +677,10 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) err = model_send(model, &tx, true, sdu, &pub_sent_cb, model); if (err) { pub->count = 0; - return err; } - return 0; + os_mbuf_free_chain(sdu); + return err; } struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c index ac106f36d..b2cd4ed7e 100644 --- a/nimble/host/mesh/src/friend.c +++ b/nimble/host/mesh/src/friend.c @@ -408,6 +408,7 @@ static struct os_mbuf *encode_update(struct bt_mesh_friend *frnd, u8_t md) struct bt_mesh_ctl_friend_update *upd; struct os_mbuf *sdu = NET_BUF_SIMPLE(1 + sizeof(*upd)); struct bt_mesh_subnet *sub = bt_mesh_subnet_get(frnd->net_idx); + struct os_mbuf *buf; __ASSERT_NO_MSG(sub != NULL); @@ -420,7 +421,10 @@ static struct os_mbuf *encode_update(struct bt_mesh_friend *frnd, u8_t md) upd->iv_index = sys_cpu_to_be32(bt_mesh.iv_index); upd->md = md; - return encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_UPDATE, sdu); + buf = encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_UPDATE, sdu); + + os_mbuf_free_chain(sdu); + return buf; } static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact) @@ -449,6 +453,7 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact) frnd->last = buf; frnd->send_last = 1; + os_mbuf_free_chain(sdu); } static void friend_recv_delay(struct bt_mesh_friend *frnd) @@ -755,6 +760,7 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi) frnd->last = buf; frnd->send_last = 1; + os_mbuf_free_chain(sdu); } #define RECV_WIN CONFIG_BT_MESH_FRIEND_RECV_WIN diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c index bce94a8e9..25ad8c659 100644 --- a/nimble/host/mesh/src/shell.c +++ b/nimble/host/mesh/src/shell.c @@ -751,16 +751,17 @@ static int cmd_net_send(int argc, char *argv[]) .sub = bt_mesh_subnet_get(net.net_idx), }; size_t len; - int err; + int err = 0; if (argc < 2) { - return -EINVAL; + err = -EINVAL; + goto done; } if (!tx.sub) { printk("No matching subnet for NetKey Index 0x%04x\n", net.net_idx); - return 0; + goto done; } net_buf_simple_init(msg, 0); @@ -772,7 +773,9 @@ static int cmd_net_send(int argc, char *argv[]) printk("Failed to send (err %d)\n", err); } - return 0; +done: + os_mbuf_free_chain(msg); + return err; } struct shell_cmd_help cmd_net_send_help = { @@ -909,9 +912,9 @@ struct shell_cmd_help cmd_timeout_help = { static int cmd_get_comp(int argc, char *argv[]) { - struct os_mbuf*comp = NET_BUF_SIMPLE(32); + struct os_mbuf *comp = NET_BUF_SIMPLE(32); u8_t status, page = 0x00; - int err; + int err = 0; if (argc > 1) { page = strtol(argv[1], NULL, 0); @@ -922,12 +925,12 @@ static int cmd_get_comp(int argc, char *argv[]) &status, comp); if (err) { printk("Getting composition failed (err %d)\n", err); - return 0; + goto done; } if (status != 0x00) { printk("Got non-success status 0x%02x\n", status); - return 0; + goto done; } printk("Got Composition Data for 0x%04x:\n", net.dst); @@ -979,7 +982,9 @@ static int cmd_get_comp(int argc, char *argv[]) } } - return 0; +done: + os_mbuf_free_chain(comp); + return err; } struct shell_cmd_help cmd_get_comp_help = {