diff options
-rw-r--r-- | main/cdr.c | 6 | ||||
-rw-r--r-- | res/res_pjproject.c | 2 | ||||
-rw-r--r-- | res/res_pjsip_outbound_registration.c | 6 | ||||
-rw-r--r-- | res/res_pjsip_session.c | 80 |
4 files changed, 50 insertions, 44 deletions
diff --git a/main/cdr.c b/main/cdr.c index 1424607c9..60532fe9f 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -3384,7 +3384,8 @@ static int cdr_object_update_party_b_userfield_cb(void *obj, void *arg, void *da ast_assert(cdr->party_b.snapshot && !strcasecmp(cdr->party_b.snapshot->name, info->channel_name)); - strcpy(cdr->party_b.userfield, info->userfield); + ast_copy_string(cdr->party_b.userfield, info->userfield, + sizeof(cdr->party_b.userfield)); } return 0; @@ -3407,7 +3408,8 @@ void ast_cdr_setuserfield(const char *channel_name, const char *userfield) if (it_cdr->fn_table == &finalized_state_fn_table && it_cdr->next != NULL) { continue; } - ast_copy_string(it_cdr->party_a.userfield, userfield, AST_MAX_USER_FIELD); + ast_copy_string(it_cdr->party_a.userfield, userfield, + sizeof(it_cdr->party_a.userfield)); } ao2_unlock(cdr); } diff --git a/res/res_pjproject.c b/res/res_pjproject.c index c2f7c843d..16fe01aa4 100644 --- a/res/res_pjproject.c +++ b/res/res_pjproject.c @@ -236,7 +236,7 @@ static void capture_buildopts_cb(int level, const char *data, int len) } dup = ast_strdup(ast_skip_blanks(data)); - if (AST_VECTOR_ADD_SORTED(&buildopts, dup, strcmp)) { + if (dup && AST_VECTOR_ADD_SORTED(&buildopts, dup, strcmp)) { ast_free(dup); } } diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c index 731a1a939..0b177ae32 100644 --- a/res/res_pjsip_outbound_registration.c +++ b/res/res_pjsip_outbound_registration.c @@ -1386,10 +1386,10 @@ static int sip_outbound_registration_perform(void *data) AST_VECTOR_INIT(&state->client_state->outbound_auths, AST_VECTOR_SIZE(®istration->outbound_auths)); for (i = 0; i < AST_VECTOR_SIZE(®istration->outbound_auths); ++i) { - const char *name = ast_strdup(AST_VECTOR_GET(®istration->outbound_auths, i)); + char *name = ast_strdup(AST_VECTOR_GET(®istration->outbound_auths, i)); - if (name) { - AST_VECTOR_APPEND(&state->client_state->outbound_auths, name); + if (name && AST_VECTOR_APPEND(&state->client_state->outbound_auths, name)) { + ast_free(name); } } state->client_state->retry_interval = registration->retry_interval; diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index c53d52d71..f2ee3478b 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -2654,6 +2654,36 @@ static void session_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e) /* XXX STUB */ } +static int session_end_if_disconnected(int id, pjsip_inv_session *inv) +{ + struct ast_sip_session *session; + + if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { + return 0; + } + + /* + * We are locking because ast_sip_dialog_get_session() needs + * the dialog locked to get the session by other threads. + */ + pjsip_dlg_inc_lock(inv->dlg); + session = inv->mod_data[id]; + inv->mod_data[id] = NULL; + pjsip_dlg_dec_lock(inv->dlg); + + /* + * Pass the session ref held by session->inv_session to + * session_end_completion(). + */ + if (session + && ast_sip_push_task(session->serializer, session_end_completion, session)) { + /* Do it anyway even though this is not the right thread. */ + session_end_completion(session); + } + + return 1; +} + static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e) { ast_sip_session_response_cb cb; @@ -2678,6 +2708,17 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans /* The session has ended. Ignore the transaction change. */ return; } + + /* + * If the session is disconnected really nothing else to do unless currently transacting + * a BYE. If a BYE then hold off destruction until the transaction timeout occurs. This + * has to be done for BYEs because sometimes the dialog can be in a disconnected + * state but the BYE request transaction has not yet completed. + */ + if (tsx->method.id != PJSIP_BYE_METHOD && session_end_if_disconnected(id, inv)) { + return; + } + switch (e->body.tsx_state.type) { case PJSIP_EVENT_TX_MSG: /* When we create an outgoing request, we do not have access to the transaction that @@ -2800,49 +2841,12 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans } break; case PJSIP_EVENT_TRANSPORT_ERROR: - if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { - /* - * Clear the module data now to block session_inv_on_state_changed() - * from calling session_end() if it hasn't already done so. - */ - inv->mod_data[id] = NULL; - - /* - * Pass the session ref held by session->inv_session to - * session_end_completion(). - */ - if (session - && ast_sip_push_task(session->serializer, session_end_completion, session)) { - /* Do it anyway even though this is not the right thread. */ - session_end_completion(session); - } - return; - } - break; case PJSIP_EVENT_TIMER: /* * The timer event is run by the pjsip monitor thread and not * by the session serializer. */ - if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { - /* - * We are locking because ast_sip_dialog_get_session() needs - * the dialog locked to get the session by other threads. - */ - pjsip_dlg_inc_lock(inv->dlg); - session = inv->mod_data[id]; - inv->mod_data[id] = NULL; - pjsip_dlg_dec_lock(inv->dlg); - - /* - * Pass the session ref held by session->inv_session to - * session_end_completion(). - */ - if (session - && ast_sip_push_task(session->serializer, session_end_completion, session)) { - /* Do it anyway even though this is not the right thread. */ - session_end_completion(session); - } + if (session_end_if_disconnected(id, inv)) { return; } break; |