diff options
author | Joshua Colp <jcolp@digium.com> | 2016-02-04 12:35:37 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-02-04 12:35:37 -0600 |
commit | d8f1a74d15b49657d65d56b92bb744d54eda37b6 (patch) | |
tree | bbb9f88b4736e86fea9aa41915b77b003480d5ec | |
parent | 299278c45b5a24b708634b09566047d42724fc39 (diff) | |
parent | 82e2938fa873f9d680b7924ac5c9822fd1995a84 (diff) |
Merge "res_stasis_device_state: Fix refcounting error."
-rw-r--r-- | res/res_stasis_device_state.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c index 40936460c..453bfae6d 100644 --- a/res/res_stasis_device_state.c +++ b/res/res_stasis_device_state.c @@ -303,6 +303,12 @@ static void device_state_cb(void *data, struct stasis_subscription *sub, { 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; } @@ -365,10 +371,12 @@ static int subscribe_device_state(struct stasis_app *app, void *obj) ast_debug(3, "Subscribing to device %s\n", sub->device_name); - sub->sub = stasis_subscribe_pool(topic, device_state_cb, sub); + sub->sub = stasis_subscribe_pool(topic, 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; } |