Index: main/channel.c =================================================================== --- main/channel.c (revision 258775) +++ main/channel.c (working copy) @@ -4935,8 +4935,8 @@ ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", clonechan->name, clonechan->masqr->name); } else { - original->masq = clonechan; - clonechan->masqr = original; + original->masq = ast_channel_ref(clonechan); + clonechan->masqr = ast_channel_ref(original); ast_queue_frame(original, &ast_null_frame); ast_queue_frame(clonechan, &ast_null_frame); ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); @@ -5282,7 +5282,7 @@ CHANNEL_DEADLOCK_AVOIDANCE(original); } - /* clear the masquerade channels */ + /* clear the masquerade channels - we inherit the references */ original->masq = NULL; clonechan->masqr = NULL; @@ -5556,9 +5556,14 @@ ast_channel_unlock(clonechan); ao2_link(channels, clonechan); ao2_link(channels, original); + /* Dispose of the reference inherited from masq/masqr */ + ast_channel_unref(clonechan); + ast_channel_unref(original); } else { ast_channel_unlock(original); ao2_link(channels, original); + /* Dispose of the reference inherited from masq/masqr */ + ast_channel_unref(original); } return 0; }