assigned-uniqueids: Miscellaneous cleanup and fixes.

* Fix memory leak in ast_unreal_new_channels().  Made it generate the ;2
uniqueid on a stack variable instead of mallocing it.

* Made send error response to ARI and AMI requests instead of just logging
excessive uniqueid length and allowing truncation.  action_originate() and
ari_channels_handle_originate_with_id().

* Fixed minor truncating uniqueid hole when generating the ;2 uniqueid
string length.  Created public and internal lengths of uniqueid.  The
internal length can handle a max public uniqueid plus an appended ;2.

* free() and ast_free() are NULL tolerant so they don't need a NULL test
before calling.

* Made use better struct initialization format instead of the position
dependent initialization format.  Also anything not explicitly initialized
in the struct is initialized to zero by the compiler.

* Made ast_channel_internal_set_fake_ids() use the safer
ast_copy_string() instead of strncpy().

Review: https://reviewboard.asterisk.org/r/3371/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@410949 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2014-03-20 16:27:49 +00:00
parent c2dd050e1a
commit ce6048c07f
8 changed files with 77 additions and 45 deletions

View File

@@ -249,8 +249,7 @@ int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device,
channel->device = ast_strdup(device);
/* Store the assigned id */
if (assignedids && !ast_strlen_zero(assignedids->uniqueid))
{
if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
channel->assignedid1 = ast_strdup(assignedids->uniqueid);
if (!ast_strlen_zero(assignedids->uniqueid2)) {
@@ -276,7 +275,10 @@ static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channe
char numsubst[AST_MAX_EXTENSION];
struct ast_format_cap *cap_all_audio = NULL;
struct ast_format_cap *cap_request;
struct ast_assigned_ids assignedids = {channel->assignedid1, channel->assignedid2};
struct ast_assigned_ids assignedids = {
.uniqueid = channel->assignedid1,
.uniqueid2 = channel->assignedid2,
};
/* Copy device string over */
ast_copy_string(numsubst, channel->device, sizeof(numsubst));
@@ -431,14 +433,10 @@ static int handle_call_forward(struct ast_dial *dial, struct ast_dial_channel *c
/* Drop old destination information */
ast_free(channel->tech);
ast_free(channel->device);
if (channel->assignedid1) {
ast_free(channel->assignedid1);
channel->assignedid1 = NULL;
}
if (channel->assignedid2) {
ast_free(channel->assignedid2);
channel->assignedid2 = NULL;
}
ast_free(channel->assignedid1);
channel->assignedid1 = NULL;
ast_free(channel->assignedid2);
channel->assignedid2 = NULL;
/* Update the dial channel with the new destination information */
channel->tech = ast_strdup(tech);
@@ -1023,12 +1021,8 @@ int ast_dial_destroy(struct ast_dial *dial)
/* Free structure */
ast_free(channel->tech);
ast_free(channel->device);
if (channel->assignedid1) {
ast_free(channel->assignedid1);
}
if (channel->assignedid2) {
ast_free(channel->assignedid2);
}
ast_free(channel->assignedid1);
ast_free(channel->assignedid2);
AST_LIST_REMOVE_CURRENT(list);
ast_free(channel);