-
Notifications
You must be signed in to change notification settings - Fork 61
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 memory leak that occurs when exceptions occur in stacked segments #123
Conversation
ok jenkins |
I was unable to create an automated test to reproduce this. Here is the manual approach I used should we want to try again in the future. Create a php file with the following contents: <?php
function recursiveCount(int $level): void
{
if ($level <= 1) {
//throw new \Exception('Oops');
return;
}
recursiveCount($level - 1);
}
for($i= 0; $i<2; ++$i) {
try {
recursiveCount(1);
} catch(\Exception $e) {
// continue
}
} Ensure that distributed tracing is enabled and that tracer details are set to Run the script under Increasing the recursion count and the number of iterations through the loop will also help to increase the chances of causing a memory leak. The leak occurs when there are short lived segments that remain on the stack and that throw an exception. |
ok jenkins |
99c617f
to
105b958
Compare
ok jenkins |
1 similar comment
ok jenkins |
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 done! Thanks for investigating and fixing this!
This PR fixes a couple of memory leaks introduced in v9.12 of the agent.
nr_php_error_record_exception_segment
.segment->error
when an exception occurs in a stacked segment that is not converted to a heap segment.The fix for the latter involves converting the stacked segment to a heap allocated segment prior to deallocation if
segment->error
is set. The pre-existing code does the same thing ifsegment->attributes
is set.