Summary: | ASTERISK-19461: ChanSpy - Improper refcounts avoid channel release | ||
Reporter: | Irontec (irontec) | Labels: | |
Date Opened: | 2012-03-02 03:46:43.000-0600 | Date Closed: | 2012-03-02 09:52:19.000-0600 |
Priority: | Major | Regression? | |
Status: | Closed/Complete | Components: | Applications/app_chanspy |
Versions: | SVN | Frequency of Occurrence | |
Related Issues: | |||
Environment: | Attachments: | ( 0) app_chanspy_iteartor_next_unref.patch | |
Description: | After testing a bit ChanSpy with SPYGROUPS (g flag) we have discovered that spy channels are not properly released. Afaik, channels are removed from groups when their refcount reaches 0. After enabling REF_DEBUG we found that this was not happening: {noformat} [...] 0x3038238 -1 cli.c:1504:handle_showchan () [@66] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@65] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@66] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@67] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@68] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@69] 0x3038238 +1 channel.c:1627:ast_channel_iterator_next () [@70] 0x3038238 -1 cli.c:896:handle_chanlist () [@71] [...] {noformat} It seems ast_channel_iterator_next returns the next channel in the iterator with a ref, avoiding the channel to be destroyed before we have finished with it, so we have to unref it before the next interation. After digging a bit, we found that next_channel function may be bugged, and is some cases it doesn't unref the channel before the next iteration. =========================================================================== {code} redo: if (!(next = ast_channel_iterator_next(iter))) { return NULL; } if (!strncmp(ast_channel_name(next), "DAHDI/pseudo", pseudo_len)) { goto redo; } else if (next == chan) { goto redo; } autochan_store = ast_autochan_setup(next); ast_channel_unref(next); {code} =========================================================================== I'm not an expert but I've attached a patch, if you find a better solution feel free to implement it :) | ||
Comments: | By: Irontec (irontec) 2012-03-02 03:47:57.809-0600 Unrefs the channel before next iteration. By: Irontec (irontec) 2012-03-02 03:51:37.043-0600 This may fix some other issues like @ASTERISK-17515 |