Index: main/channel.c =================================================================== --- main/channel.c (revision 368407) +++ main/channel.c (working copy) @@ -3558,6 +3558,12 @@ res = ast_timer_set_rate(c->timer, real_rate); + /* Only ast_channel and ast_filestream are passed as data. Both are ao2 objects, so a ref needs to be taken + * if we are going to store it. This is kind of weird for a channel, but for filestream it is necessary to + * make sure that the filestream doesn't disappear when the timingfunc is called. */ + if (data && c->timingdata != data) { + ao2_ref(data, +1); + } c->timingfunc = func; c->timingdata = data; @@ -3569,6 +3575,9 @@ * miss any important frames. */ c->fdno = -1; + if (c->timingdata) { + ao2_ref(c->timingdata, -1); + } } ast_channel_unlock(c);