Return without Gosub: stack is unallocated

Dear all,

Is there a way to check if the gosub stack is empty?

The goal is avoid to call Return if the stack is empty because it causes an error on execution:

-- Executing [351@usuarios:4] Return("PJSIP/203-00000010", "") in new stack}}
-- [2019-07-01 11:33:26.972] ERROR[27565][C-00000009]: app_stack.c:389 return_exec: Return without Gosub: stack is unallocated

In my case, the same extension can be called directly or via Gosub from other contexts (for avoiding duplication), the problem is when the call is directly placed because the stack is empty and I will get an error.

Replacing the calls with Goto is not possible because I need to continue the dialplan execution when calling from other contexts.

I saw the StackPop application but it doesn’t fit the needs because remove elements from stack.

I could control with custom variables but I was looking for a more elegant way.


Try looking into the LOCAL_PEEK and STACK_PEEK functions.

STACK_PEEK looks fine for my purposes but has the same problem.

When the stack is empty and you try to read with STACK_PEEK function it causes an error:

[2019-07-02 12:54:01.984] ERROR[30101][C-0000001f]: app_stack.c:880 stackpeek_read: Stack peek of ‘1’ is more stack frames than I have

This seems to be a good method insert a custom variable before return if stack is empty

Yes, finally I did it with a custom variable and GotoIf for sending to Return() when needed.

But that error doesn’t block call flow, and in Asterisk 16 the third option to STACK_PEEK function is a boolean that lets you suppress these sorts of errors.

Anyhow, the result of STACK_PEEK is non-empty when in Gosub vs. empty string when not in Gosub. So I think this might be all you need in the Gosub – no custom variables:

1 Like

I already tried by this way with your first comment. I tried it in asterisk v16 with suppress warning set on STACK_PEEK function, the exact command you posted in this comment but it generates a error when the stack is empty.

I tried it again making a copy paste of your command to assure that I didn’t missed anything and now I have the same error:

[2019-07-08 13:19:04.085] ERROR[2627][C-00000004]: app_stack.c:855 stackpeek_read: STACK_PEEK must be called with a positive peek value

The error doesn’t block the call flow, but if your call is from a trunk… this error makes the ${DIALSTATUS} in the other party will be: CHANUNAVAIL

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.