Index: asterisk-1.6.2.22/main/file.c =================================================================== --- asterisk-1.6.2.22.orig/main/file.c 2012-03-13 17:23:02.000000000 +0000 +++ asterisk-1.6.2.22/main/file.c 2012-03-15 16:54:36.000000000 +0000 @@ -739,6 +739,14 @@ { int whennext = 0; + if (!s->owner) { + ast_log(LOG_WARNING, "No Stream owner during playback (1)!\n"); + return FSREAD_FAILURE; + } + + /* Sometone else (masq) may close the strem on us, so claim ownership. */ + ao2_ref(s, +1); + while (!whennext) { struct ast_frame *fr; @@ -761,7 +769,7 @@ } } - if (whennext != s->lasttimeout) { + if (s->owner && whennext != s->lasttimeout) { if (s->owner->timingfd > -1) { float samp_rate = (float) ast_format_rate(s->fmt->format); unsigned int rate; @@ -774,13 +783,18 @@ whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_audio, s); } s->lasttimeout = whennext; + ao2_ref(s, -1); return FSREAD_SUCCESS_NOSCHED; } + ao2_ref(s, -1); return FSREAD_SUCCESS_SCHED; return_failure: - s->owner->streamid = -1; - ast_settimeout(s->owner, 0, NULL, NULL); + if( s->owner ) { + s->owner->streamid = -1; + ast_settimeout(s->owner, 0, NULL, NULL); + } + ao2_ref(s, -1); return FSREAD_FAILURE; } @@ -803,6 +817,14 @@ { int whennext = 0; + if (!s->owner) { + ast_log(LOG_WARNING, "No VStream owner during playback (1)!\n"); + return FSREAD_FAILURE; + } + + /* Sometone else (masq) may close the strem on us, so claim ownership. */ + ao2_ref(s, +1); + while (!whennext) { struct ast_frame *fr = read_frame(s, &whennext); @@ -812,6 +834,7 @@ ast_frfree(fr); } s->owner->vstreamid = -1; + ao2_ref(s, -1); return FSREAD_FAILURE; } @@ -820,14 +843,16 @@ } } - if (whennext != s->lasttimeout) { + if (s->owner && whennext != s->lasttimeout) { s->owner->vstreamid = ast_sched_add(s->owner->sched, whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_video, s); s->lasttimeout = whennext; + ao2_ref(s, -1); return FSREAD_SUCCESS_NOSCHED; } + ao2_ref(s, -1); return FSREAD_SUCCESS_SCHED; } @@ -904,6 +930,8 @@ f->owner->vstream = NULL; AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid); } + /* Chan no longer points at stream, so stream should not point at chan */ + f->owner = NULL; } ao2_ref(f, -1);