summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/pbx.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/main/pbx.c b/main/pbx.c
index d814c5ac6..b605a9143 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -9791,13 +9791,7 @@ static int add_priority(struct ast_context *con, struct ast_exten *tmp,
"Unable to register extension '%s' priority %d in '%s', already in use\n",
tmp->exten, tmp->priority, con->name);
}
- if (tmp->datad) {
- tmp->datad(tmp->data);
- /* if you free this, null it out */
- tmp->data = NULL;
- }
- ast_free(tmp);
return -1;
}
/* we are replacing e, so copy the link fields and then update
@@ -10081,6 +10075,26 @@ static int ast_add_extension2_lockopt(struct ast_context *con,
}
if (e && res == 0) { /* exact match, insert in the priority chain */
res = add_priority(con, tmp, el, e, replace);
+ if (res < 0) {
+ if (con->pattern_tree) {
+ struct match_char *x = add_exten_to_pattern_tree(con, tmp, 1);
+
+ if (x->exten) {
+ x->deleted = 1;
+ x->exten = 0;
+ }
+
+ ast_hashtab_remove_this_object(con->root_table, tmp);
+ }
+
+ if (tmp->datad) {
+ tmp->datad(tmp->data);
+ /* if you free this, null it out */
+ tmp->data = NULL;
+ }
+
+ ast_free(tmp);
+ }
if (lock_context) {
ast_unlock_context(con);
}