Skip to content

Fixed incorrect call count upon message sending failure when making call #4410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025

Conversation

sauwming
Copy link
Member

To fix #4384.

If pjsip_inv_send_msg() fails, the call count is not reverted.

/* Must increment call counter now */
++pjsua_var.call_cnt;

/* Send initial INVITE: */
status = pjsip_inv_send_msg(inv, tdata);
if (status != PJ_SUCCESS) {
    cb_called = PJ_TRUE;

    /* Upon failure to send first request, the invite
     * session would have been cleared.
     */
    call->inv = inv = NULL;
    goto on_error;
}

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the call counter was incorrectly left incremented when pjsip_inv_send_msg() failed, potentially causing call count mismatches.

  • Reverts the earlier increment of the call counter by decrementing it upon failure.
  • Separates the nullification of the invite pointer from the resetting of the local variable.
Comments suppressed due to low confidence (2)

pjsip/src/pjsua-lib/pjsua_call.c:580

  • Reverting the call count increment via a direct decrement is appropriate; however, please ensure that pjsua_var.call_cnt does not become negative in any failure scenarios.
--pjsua_var.call_cnt;

pjsip/src/pjsua-lib/pjsua_call.c:579

  • Removing the assignment 'inv = NULL' is acceptable as long as subsequent error handling relies solely on call->inv. Please verify that no other cleanup logic depends on the local variable 'inv'.
call->inv = NULL;

@@ -576,7 +576,8 @@ on_make_call_med_tp_complete(pjsua_call_id call_id,
/* Upon failure to send first request, the invite
* session would have been cleared.
*/
call->inv = inv = NULL;
call->inv = NULL;
--pjsua_var.call_cnt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some/most paths of pjsip_inv_send_msg() failure seem to invoke on_state_changed(PJSIP_INV_STATE_DISCONNECTED) which eventually will decrement the 'pjsua_var.call_cnt', so after this patch, the call counter may be decremented twice?

@sauwming sauwming merged commit b9619cd into master Apr 28, 2025
40 of 41 checks passed
@sauwming sauwming deleted the call-fail branch April 28, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pjsua_var.call_cnt remains incremented if pjsip_tsx_create_uac fails, causing incorrect call count
2 participants