Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Mesh: Virtual address memory leak #28279

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions subsys/bluetooth/mesh/cfg_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ static struct bt_mesh_cfg_srv *conf;

static struct label labels[CONFIG_BT_MESH_LABEL_COUNT];

#if CONFIG_BT_MESH_LABEL_COUNT > 0
static uint8_t va_del(uint8_t *label_uuid, uint16_t *addr);
#endif

static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
bool primary)
{
Expand Down Expand Up @@ -234,6 +238,16 @@ static uint8_t _mod_pub_set(struct bt_mesh_model *model, uint16_t pub_addr,
return STATUS_INVALID_APPKEY;
}

#if CONFIG_BT_MESH_LABEL_COUNT > 0
if (BT_MESH_ADDR_IS_VIRTUAL(model->pub->addr)) {
uint8_t *uuid = bt_mesh_label_uuid_get(model->pub->addr);

if (uuid) {
va_del(uuid, NULL);
}
}
#endif

model->pub->addr = pub_addr;
model->pub->key = app_idx;
model->pub->cred = cred_flag;
Expand Down Expand Up @@ -1230,9 +1244,14 @@ static void mod_pub_va_set(struct bt_mesh_model *model,
}

status = va_add(label_uuid, &pub_addr);
if (status == STATUS_SUCCESS) {
status = _mod_pub_set(mod, pub_addr, pub_app_idx, cred_flag,
pub_ttl, pub_period, retransmit, true);
if (status != STATUS_SUCCESS) {
goto send_status;
}

status = _mod_pub_set(mod, pub_addr, pub_app_idx, cred_flag, pub_ttl,
pub_period, retransmit, true);
if (status != STATUS_SUCCESS) {
va_del(label_uuid, NULL);
}

send_status:
Expand Down Expand Up @@ -1800,13 +1819,15 @@ static void mod_sub_va_add(struct bt_mesh_model *model,
if (bt_mesh_model_find_group(&mod, sub_addr)) {
/* Tried to add existing subscription */
status = STATUS_SUCCESS;
va_del(label_uuid, NULL);
goto send_status;
}


entry = bt_mesh_model_find_group(&mod, BT_MESH_ADDR_UNASSIGNED);
if (!entry) {
status = STATUS_INSUFF_RESOURCES;
va_del(label_uuid, NULL);
goto send_status;
}

Expand Down Expand Up @@ -1935,11 +1956,11 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model,


if (ARRAY_SIZE(mod->groups) > 0) {
bt_mesh_model_tree_walk(bt_mesh_model_root(mod),
mod_sub_clear_visitor, NULL);

status = va_add(label_uuid, &sub_addr);
if (status == STATUS_SUCCESS) {
bt_mesh_model_tree_walk(bt_mesh_model_root(mod),
mod_sub_clear_visitor, NULL);
mod->groups[0] = sub_addr;

if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
Expand Down