Index: main/autoservice.c =================================================================== --- main/autoservice.c (revision 412225) +++ main/autoservice.c (working copy) @@ -131,6 +131,14 @@ callid = ast_channel_callid(chan); ast_callid_threadassoc_change(callid); + if (callid) { + /* + * Release the callid ref but keep callid non-NULL in case + * execution ever breaks out of the forever loop so we will + * know to cleanup. + */ + ast_callid_unref(callid); + } f = ast_read(chan); @@ -175,8 +183,12 @@ } if (callid) { + /* + * At this point callid does not have a ref. + * We only care if it is non-NULL to cleanup the + * thread's ref. + */ ast_callid_threadassoc_remove(); - callid = ast_callid_unref(callid); } asthread = AST_PTHREADT_NULL;