diff --git a/main/pbx.c b/main/pbx.c
index 221e5173f80599b203dcf17854c86d188ff3571e..905310ccf34f30e14d7c4f530ace9d77494c7cea 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3257,6 +3257,7 @@ const char *ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, stru
 	int offset, length;
 	int i, need_substring;
 	struct varshead *places[2] = { headp, &globals };	/* list of places where we may look */
+	char workspace[20];
 
 	if (c) {
 		ast_channel_lock(c);
@@ -3352,7 +3353,6 @@ const char *ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, stru
 		} else if (!strcmp(var, "ASTLOGDIR")) {
 			s = ast_config_AST_LOG_DIR;
 		} else if (!strcmp(var, "ENTITYID")) {
-			char workspace[20];
 			ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default);
 			s = workspace;
 		}