pbx.c: On error, ast_add_extension2_lockopt should always free 'data'

In the event that the desired extension already exists,
ast_add_extension2_lockopt() will free the 'data' it is passed before
returning an error, so we should not be freeing it ourselves.

Additionally, there were two places where ast_add_extension2_lockopt()
could return an error without also freeing the 'data' pointer, so we
add that.

ASTERISK-29097 #close

Change-Id: I904707aae55169feda050a5ed7c6793b53fe6eae
This commit is contained in:
Sean Bright
2020-09-29 14:04:48 -04:00
committed by George Joseph
parent 4a049ad510
commit 5a0b19a4f3
5 changed files with 17 additions and 6 deletions

View File

@@ -660,7 +660,6 @@ static int parking_duration_callback(struct ast_bridge_channel *bridge_channel,
dial_string_flat, PARK_DIAL_CONTEXT, ast_get_extension_registrar(existing_exten));
} else if (ast_add_extension2_nolock(park_dial_context, 1, dial_string_flat, 1, NULL, NULL,
"Dial", duplicate_returnexten, ast_free_ptr, BASE_REGISTRAR, NULL, 0)) {
ast_free(duplicate_returnexten);
ast_log(LOG_ERROR, "Failed to create parking redial parker extension %s@%s - Dial(%s)\n",
dial_string_flat, PARK_DIAL_CONTEXT, returnexten);
}

View File

@@ -721,7 +721,6 @@ static int parking_add_extension(struct ast_context *context, int replace, const
if (ast_add_extension2_nolock(context, replace, extension, priority, NULL, NULL,
application, data_duplicate, ast_free_ptr, registrar, NULL, 0)) {
ast_free(data_duplicate);
return -1;
}

View File

@@ -475,7 +475,6 @@ static int add_extension(struct ast_context *context, const char *exten,
if (ast_add_extension2_nolock(context, 0, exten, priority, NULL, NULL,
app, data, free_ptr, BASE_REGISTRAR, NULL, 0)) {
ast_free(data);
return -1;
}