Index: apps/app_macro.c =================================================================== --- apps/app_macro.c (revision 8372) +++ apps/app_macro.c (working copy) @@ -104,7 +104,7 @@ char *offsets; int offset, depth; int setmacrocontext=0; - int autoloopflag; + int autoloopflag, dead = 0; char *save_macro_exten; char *save_macro_context; @@ -216,8 +216,8 @@ break; } switch(res) { - case MACRO_EXIT_RESULT: - res = 0; + case MACRO_EXIT_RESULT: + res = 0; goto out; case AST_PBX_KEEPALIVE: if (option_debug) @@ -231,6 +231,7 @@ ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro); else if (option_verbose > 1) ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro); + dead = 1; goto out; } } @@ -250,37 +251,44 @@ out: /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */ 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); - for (x=1; xmacrocontext[0] = '\0'; chan->macroexten[0] = '\0'; chan->macropriority = 0; } - if (!strcasecmp(chan->context, fullmacro)) { + if (!dead && !strcasecmp(chan->context, fullmacro)) { /* If we're leaving the macro normally, restore original information */ chan->priority = oldpriority; ast_copy_string(chan->context, oldcontext, sizeof(chan->context)); @@ -299,7 +307,8 @@ } } - pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset); + if (!dead) + pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset); if (save_macro_offset) free(save_macro_offset); LOCAL_USER_REMOVE(u);