diff --git a/apps/app_forkcdr.c b/apps/app_forkcdr.c index c75553c347a45535b0002c17760cc66ad2ee3ada..354792fb9a49d80b8b6e7154a95aaff66894a8d4 100644 --- a/apps/app_forkcdr.c +++ b/apps/app_forkcdr.c @@ -191,6 +191,14 @@ static void ast_cdr_fork(struct ast_channel *chan, struct ast_flags optflags, ch if (!(newcdr = ast_cdr_dup_unique(cdr))) return; + /* + * End the original CDR if requested BEFORE appending the new CDR + * otherwise we incorrectly end the new CDR also. + */ + if (ast_test_flag(&optflags, OPT_ENDCDR)) { + ast_cdr_end(cdr); + } + ast_cdr_append(cdr, newcdr); if (!ast_test_flag(&optflags, OPT_NORESET)) @@ -218,9 +226,6 @@ static void ast_cdr_fork(struct ast_channel *chan, struct ast_flags optflags, ch if (ast_test_flag(&optflags, OPT_RESETDEST)) newcdr->dstchannel[0] = 0; - if (ast_test_flag(&optflags, OPT_ENDCDR)) - ast_cdr_end(cdr); - if (ast_test_flag(&optflags, OPT_ANSLOCK)) ast_set_flag(cdr, AST_CDR_FLAG_ANSLOCKED);