-
Notifications
You must be signed in to change notification settings - Fork 802
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
Fix tdata leak when pjsip_inv_initial_answer() return error #3741
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the ref count is not decremented when not-success, but below after
pjsip_timer_update_resp
it is decremented. Is it okay?Also, please make sure that the pattern is consistent for every
pjsip_dlg_modify_response
in the lib.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the
tdata->ref_cnt
will be 2 whenpjsip_inv_initial_answer()
returns.e.g: the
pjsip_tx_data_dec_ref()
afterpjsip_timer_update_resp()
will not release thetdata
.I think setting the
tdata->last_answer
would be better to avoid the inconsistency and let inv/tsx decrement it later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inv->last_answer
is fine only whenp_tdata
is set (so app will send it or dec ref it), otherwise it will still leak?pjsip_dlg_modify_response
does not mention about add ref count in its spec/doc, I think it's better to add it now.process_answer()
fails, it seems that the tdata ref count is not properly decremented? (need test all affected scenarios to make sure things are fine).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pjsip_dlg_modify_response
. So, it will still leak even ifp_tdata
is not set. We can setinv->last_answer
only ifp_tdata
is set, however we need to call an additionalpjsip_tx_data_dec_ref
in the casep_tdata
is not set.pjsip_dlg_modify_response
. We need to an additionalpjsip_tx_data_dec_ref
e.g:
pjproject/pjsip/src/pjsip-ua/sip_inv.c
Line 2758 in 43dd94f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually a bit puzzled as to why we need to add tdata ref in
pjsip_dlg_modify_response()
. Is there a way for us to avoid adding the ref?From the code, it states: "Must add reference counter, since tsx_send_msg() will decrement it." And it will probably causes crash if we remove it, but perhaps there's another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the API has been there since the beginning, see here, so I think modifying the behavior will cause a major backward compatibility issue.
We can always introduce an alternative API (without add ref) and replace all usages of the old one in the library, but perhaps too much hassle and we may still need to maintain the old one for quite some time for existing apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if it introduces backward incompatibility, I agree that we shouldn't change it. Also, we don't need to create additional API since it's not a major issue.
I was just wondering why we need the additional tdata ref increment inside
modify()
, and making the tdata ref to become two, while if we usecreate()
, it seems that the tdata ref is only one before we send it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a guess. Perhaps because
modify_response()
is designated to work with a savedtdata
such asinv->last_answer
ortsx->last_tx
, so the savedtdata
will not be destroyed after being sent, e.g: