diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 31cc391300..b2a92ae57e 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -304,8 +304,8 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in while (state->sample_queue > 0) { if ((f = moh_files_readframe(chan))) { state->samples += f->samples; - res = ast_write(chan, f); state->sample_queue -= f->samples; + res = ast_write(chan, f); ast_frfree(f); if (res < 0) { ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));