{
struct ast_device_state_message *device_state;
+ if (stasis_subscription_final_message(sub, msg)) {
+ /* Remove stasis subscription's reference to device_state_subscription */
+ ao2_ref(data, -1);
+ return;
+ }
+
if (ast_device_state_message_type() != stasis_message_type(msg)) {
return;
}
return 0;
}
- if (!(sub->sub = stasis_subscribe_pool(
- ast_device_state_topic(sub->device_name),
- device_state_cb, sub))) {
+ sub->sub = stasis_subscribe_pool(ast_device_state_topic(sub->device_name),
+ device_state_cb, ao2_bump(sub));
+ if (!sub->sub) {
ast_log(LOG_ERROR, "Unable to subscribe to device %s\n",
sub->device_name);
+ /* Reference we added when attempting to stasis_subscribe_pool */
+ ao2_ref(sub, -1);
return -1;
}