Skip to content

Commit b2d1e78

Browse files
committed
downlink: handle downlink context and packetizer allocation errors
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
1 parent 2db7eeb commit b2d1e78

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/bt/downlink.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,24 @@ struct pouch_gateway_downlink_context *pouch_gateway_downlink_start(struct bt_co
167167
}
168168

169169
node->downlink_ctx = pouch_gateway_downlink_open(downlink_data_available, conn);
170+
if (node->downlink_ctx == NULL)
171+
{
172+
LOG_ERR("Failed to open downlink");
173+
free(node->downlink_scratch);
174+
node->downlink_scratch = NULL;
175+
return NULL;
176+
}
170177
node->packetizer =
171178
pouch_gatt_packetizer_start_callback(downlink_packet_fill_cb, node->downlink_ctx);
179+
if (node->packetizer == NULL)
180+
{
181+
LOG_ERR("Failed to start packetizer");
182+
pouch_gateway_downlink_close(node->downlink_ctx);
183+
node->downlink_ctx = NULL;
184+
free(node->downlink_scratch);
185+
node->downlink_scratch = NULL;
186+
return NULL;
187+
}
172188

173189
return node->downlink_ctx;
174190
}

0 commit comments

Comments
 (0)