Index: channel.c =================================================================== --- channel.c (revision 12544) +++ channel.c (working copy) @@ -1245,8 +1245,8 @@ queue->samples += f->samples; if (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) { + other_queue = (dir == SPY_WRITE) ? &spy->read_queue : &spy->write_queue; if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) { - other_queue = (dir == SPY_WRITE) ? &spy->read_queue : &spy->write_queue; if (other_queue->samples == 0) { switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) { @@ -1282,12 +1282,16 @@ if (option_debug) ast_log(LOG_DEBUG, "Spy '%s' on channel '%s' %s queue too long, dropping frames\n", spy->type, chan->name, (dir == SPY_READ) ? "read" : "write"); - while (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) { + while (queue->samples > SPY_QUEUE_SAMPLE_LIMIT && other_queue->samples > 0) { struct ast_frame *drop = queue->head; - queue->samples -= drop->samples; queue->head = drop->next; ast_frfree(drop); + + drop = other_queue->head; + other_queue->samples -= drop->samples; + other_queue->head = drop->next; + ast_frfree(drop); } } else { switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) {