[asterisk-commits] russell: branch 11 r406567 - in /branches/11: ./ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jan 26 19:14:23 CST 2014
Author: russell
Date: Sun Jan 26 19:14:19 2014
New Revision: 406567
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406567
Log:
Protect ast_filestream object when on a channel
The ast_filestream object gets tacked on to a channel via
chan->timingdata. It's a reference counted object, but the reference
count isn't used when putting it on a channel. It's theoretically
possible for another thread to interfere with the channel while it's
unlocked and cause the filestream to get destroyed.
Use the astobj2 reference count to make sure that as long as this code
path is holding on the ast_filestream and passing it into the file.c
playback code, that it knows it's valid.
Bug reported by Leif Madsen.
Review: https://reviewboard.asterisk.org/r/3135/
........
Merged revisions 406566 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/11/ (props changed)
branches/11/include/asterisk/channel.h
branches/11/main/channel.c
branches/11/main/file.c
Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/11/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/11/include/asterisk/channel.h?view=diff&rev=406567&r1=406566&r2=406567
==============================================================================
--- branches/11/include/asterisk/channel.h (original)
+++ branches/11/include/asterisk/channel.h Sun Jan 26 19:14:19 2014
@@ -901,6 +901,10 @@
* to continue.
*/
AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT = (1 << 22),
+ /*!
+ * The data on chan->timingdata is an astobj2 object.
+ */
+ AST_FLAG_TIMINGDATA_IS_AO2_OBJ = (1 << 23),
};
/*! \brief ast_bridge_config flags */
@@ -2286,6 +2290,7 @@
* \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
*/
int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
+int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj);
/*!
* \brief Transfer a channel (if supported).
Modified: branches/11/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/channel.c?view=diff&rev=406567&r1=406566&r2=406567
==============================================================================
--- branches/11/main/channel.c (original)
+++ branches/11/main/channel.c Sun Jan 26 19:14:19 2014
@@ -3555,6 +3555,11 @@
int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data)
{
+ return ast_settimeout_full(c, rate, func, data, 0);
+}
+
+int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj)
+{
int res;
unsigned int real_rate = rate, max_rate;
@@ -3578,8 +3583,19 @@
res = ast_timer_set_rate(ast_channel_timer(c), real_rate);
+ if (ast_channel_timingdata(c) && ast_test_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ)) {
+ ao2_ref(ast_channel_timingdata(c), -1);
+ }
+
ast_channel_timingfunc_set(c, func);
ast_channel_timingdata_set(c, data);
+
+ if (data && is_ao2_obj) {
+ ao2_ref(data, 1);
+ ast_set_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ);
+ } else {
+ ast_clear_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ);
+ }
if (func == NULL && rate == 0 && ast_channel_fdno(c) == AST_TIMING_FD) {
/* Clearing the timing func and setting the rate to 0
@@ -3913,9 +3929,17 @@
/* save a copy of func/data before unlocking the channel */
ast_timing_func_t func = ast_channel_timingfunc(chan);
void *data = ast_channel_timingdata(chan);
+ int got_ref = 0;
+ if (data && ast_test_flag(ast_channel_flags(chan), AST_FLAG_TIMINGDATA_IS_AO2_OBJ)) {
+ ao2_ref(data, 1);
+ got_ref = 1;
+ }
ast_channel_fdno_set(chan, -1);
ast_channel_unlock(chan);
func(data);
+ if (got_ref) {
+ ao2_ref(data, -1);
+ }
} else {
ast_timer_set_rate(ast_channel_timer(chan), 0);
ast_channel_fdno_set(chan, -1);
Modified: branches/11/main/file.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/file.c?view=diff&rev=406567&r1=406566&r2=406567
==============================================================================
--- branches/11/main/file.c (original)
+++ branches/11/main/file.c Sun Jan 26 19:14:19 2014
@@ -845,7 +845,7 @@
rate = (unsigned int) roundf(samp_rate / ((float) whennext));
- ast_settimeout(s->owner, rate, ast_fsread_audio, s);
+ ast_settimeout_full(s->owner, rate, ast_fsread_audio, s, 1);
} else {
ast_channel_streamid_set(s->owner, ast_sched_add(ast_channel_sched(s->owner), whennext / (ast_format_rate(&s->fmt->format) / 1000), ast_fsread_audio, s));
}
More information about the asterisk-commits
mailing list