diff --git a/main/pbx.c b/main/pbx.c
index b4c5d4c3aa177b18dc2f75aeef5daad1ea1cce6b..607cffbc6a6fdf2cc2b23c39ca96c42c960bb7d0 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -10503,6 +10503,7 @@ static void __ast_internal_context_destroy( struct ast_context *con)
 	}
 	tmp->root = NULL;
 	ast_rwlock_destroy(&tmp->lock);
+	ast_mutex_destroy(&tmp->macrolock);
 	ast_free(tmp);
 }
 
@@ -12173,6 +12174,10 @@ static void pbx_shutdown(void)
 		ao2_ref(statecbs, -1);
 		statecbs = NULL;
 	}
+	if (contexts_table) {
+		ast_hashtab_destroy(contexts_table, NULL);
+	}
+	pbx_builtin_clear_globals();
 }
 
 int ast_pbx_init(void)