diff --git a/main/pbx.c b/main/pbx.c
index c23b211a658e7aa8f1fc85114107eaaf7ee736e6..b665e2c01dbba16517e4ec0a85d7f5c3efaad740 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3604,7 +3604,8 @@ static struct ast_context *find_context_locked(const char *context)
 			return c;
 	}
 #endif
-	ast_unlock_contexts();
+	if (!c)
+		ast_unlock_contexts();
 
 	return c;
 }
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index 8019c5ca4c210b9324e5ce10626efebbf5966810..5c97f8bf7a61c129bee2f85d972e34954dd84c55 100644
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -1000,7 +1000,7 @@ static char *handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd,
 	if (!app_data)
 		app_data="";
 	if (ast_add_extension(a->argv[5], a->argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
-		(void *)strdup(app_data), ast_free, registrar)) {
+		(void *)strdup(app_data), ast_free_ptr, registrar)) {
 		switch (errno) {
 		case ENOMEM:
 			ast_cli(a->fd, "Out of free memory\n");