Index: main/autoservice.c =================================================================== --- main/autoservice.c (revision 90409) +++ main/autoservice.c (working copy) @@ -130,7 +130,7 @@ int ast_autoservice_start(struct ast_channel *chan) { - int res = -1; + int res = 0; struct asent *as; AST_RWLIST_WRLOCK(&aslist); @@ -144,11 +144,16 @@ } /* If not, start autoservice on channel */ - if (!as && (as = ast_calloc(1, sizeof(*as)))) { + if (as) { + /* Entry extist, autoservice is already handling this channel */ + } else if ((as = ast_calloc(1, sizeof(*as))) == NULL) { + /* Memory allocation failed */ + res = -1; + } else { + /* New entry created */ as->chan = chan; as->use_count = 1; AST_RWLIST_INSERT_HEAD(&aslist, as, list); - res = 0; if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); @@ -173,7 +178,7 @@ struct asent *as; AST_LIST_HEAD_NOLOCK(, ast_frame) dtmf_frames; struct ast_frame *f; - int removed = 1; + int removed = 0; AST_LIST_HEAD_INIT_NOLOCK(&dtmf_frames); @@ -183,11 +188,11 @@ AST_RWLIST_REMOVE_CURRENT(list); as->use_count--; if (as->use_count) { - removed = 0; break; } AST_LIST_APPEND_LIST(&dtmf_frames, &as->dtmf_frames, frame_list); ast_free(as); + removed = 1; if (!ast_check_hangup(chan)) res = 0; break;