--- app_macro.c.orig 2008-08-22 10:03:05.000000000 -0700 +++ app_macro.c 2008-08-22 11:30:55.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); }