Skip to content
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

siptrace: siptrace: fix memory leak in fake replies tracing #2295

Merged
merged 2 commits into from Apr 22, 2020

Conversation

grumvalski
Copy link
Contributor

Pre-Submission Checklist

  • Commit message has the format required by CONTRIBUTING guide
  • Commits are split per component (core, individual modules, libs, utils, ...)
  • Each component has a single commit (if not, squash them into one commit)
  • No commits to README files for modules (changes must be done to docbook files
    in doc/ subfolder, the README file is autogenerated)

Type Of Change

  • Small bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)

Checklist:

  • PR should be backported to stable branches
  • Tested changes locally
  • Related to issue #XXXX (replace XXXX with an open issue number)

Description

When tracing a faked reply (like 200 for CANCEL), the sip msg used to retrieve the tracing parameters is the transaction's uas one (uas.request) which might have the from header parsed or not, depending on the routing script actions (by default, if I'm not wrong, it is not parsed). If the header is not parsed, calling get_from in trace_onreply_out function will lead to a memory leak, beacause the header is parsed in pkg memory not freed when the transaction is deleted.

/* check if from header has been already parsed.
* If not we have to parse it in pkg memory and free iit at the end.
*/
if (msg->from && msg->from->parsed != NULL)
Copy link
Member

@miconda miconda Apr 22, 2020

Choose a reason for hiding this comment

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

Should the above condition have:

		msg->from->parsed == NULL

Otherwise it should be already parsed.

There is also a small typo in the comment: iit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, I wrongly copied from local. I'm going to fix and force push.


end:
if (faked && parsed_f)
free_from(msg->from->parsed);
Copy link
Member

Choose a reason for hiding this comment

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

At least for safety, probably msg->from->parsed should be set back to NULL, not to be freed again in other places.

@grumvalski grumvalski force-pushed the grumvalski/siptrace_memleak_fix branch from c366b54 to ee7496f Compare April 22, 2020 08:54
@miconda
Copy link
Member

miconda commented Apr 22, 2020

Looking at the function, I think two other return have to be replaced with goto end, lines 1619, 1665.

@grumvalski
Copy link
Contributor Author

Thank you Daniel and, again, you are right, I was working on 5.3 branch and didn't realize the new sip_trace_msg_attrs function. I'm pushing a fix. This also means that the patch cannot be backported to 5.3 as it is.

@@ -1383,7 +1383,7 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps)
}

if(sip_trace_msg_attrs(msg, &sto) < 0) {
return;
goto end;
}
Copy link
Member

Choose a reason for hiding this comment

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

This one is in another function -- mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, definitely not my day today...

@grumvalski grumvalski force-pushed the grumvalski/siptrace_memleak_fix branch from f2e6758 to 0f461ee Compare April 22, 2020 10:17
@miconda
Copy link
Member

miconda commented Apr 22, 2020

No worries, I had worse days. It is ok to merge. The patch doesn't look that big to be converted and applied for what 5.3 needs. Thanks.

@grumvalski grumvalski merged commit 673f25e into master Apr 22, 2020
@grumvalski grumvalski deleted the grumvalski/siptrace_memleak_fix branch April 22, 2020 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants