diff --git a/main/pbx.c b/main/pbx.c
index 43805ce7cd7c9be66ec84b042400d73d633cd9be..74aeee928aaf05475b752bf250be66d9a61222f9 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -10435,6 +10435,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);
 }
 
@@ -12142,6 +12143,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)