--- apps/app_macro.c.orig 2008-08-22 10:03:05.000000000 -0700 +++ apps/app_macro.c 2008-08-23 00:12:42.000000000 -0700 @@ -404,10 +404,13 @@ chan->priority++; } out: - /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */ + /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) + even if the channel is dead, since the channel variables may be inheritted in a device side transfer + where a new channel is created so the depth should be reset back otherwise it leads to failures + */ snprintf(depthc, sizeof(depthc), "%d", depth); + pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc); if (!dead) { - pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc); ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP); } @@ -415,10 +418,9 @@ /* Restore old arguments and delete ours */ snprintf(varname, sizeof(varname), "ARG%d", x); if (oldargs[x]) { - if (!dead) pbx_builtin_setvar_helper(chan, varname, oldargs[x]); free(oldargs[x]); - } else if (!dead) { + } else { pbx_builtin_setvar_helper(chan, varname, NULL); } }