-
Notifications
You must be signed in to change notification settings - Fork 58
fix(lsan): memory leak in perf_counter_atomic.h #384
fix(lsan): memory leak in perf_counter_atomic.h #384
Conversation
std::placeholders::_1)); | ||
} | ||
boost::shared_ptr<compute_context> ctx(new compute_context()); | ||
calc(ctx); |
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.
这里是不是可以将两句合并成一句
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.
calc(ctx); | |
calc(boost::make_shared<compute_context>()); |
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.
Note: calc(boost::make_shared<compute_context>())
result in the argument of calc(boost::shared_ptr<compute_context> &ctx)
(also contain other method) is set to const
.
Why the original code needs |
I think that it's for avoiding to use the released |
ref 5422c63 |
Right, we need consider it. I update the description of the pr:
|
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.
Change & Potential problem
In the old version, after the thread perf_counter_number_percentile_atomic is in is terminated, the timer won’t stop until the timer occurs error (for example, being canceled).
In this PR, it will stop the timer task after the thread perf_counter_number_percentile_atomic is in is terminated, we need consider whether this change haves an effect on the result of timer task for
calc(ctx)
(in line 420).
What does it mean "whether this change haves an effect on the result of timer task for calc(ctx)"? Can you write a unit test? I don't see any negative effect of removing add_ref/release_ref.
std::placeholders::_1)); | ||
} | ||
boost::shared_ptr<compute_context> ctx(new compute_context()); | ||
calc(ctx); |
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.
calc(ctx); | |
calc(boost::make_shared<compute_context>()); |
No unit test, only point the "potential problem" for reviewing and expect your advice. |
…a/rdsn into fix-mem_leak-perf_counter_atomic
Co-authored-by: Wu Tao <wutao1@xiaomi.com>
Coredump
Reason & Solution
rdsn/src/core/perf_counter/perf_counter_atomic.h
Lines 213 to 221 in 766edef
The object is added reference count by
this.add_ref()
in line 216, result in that it will be not released before the async callbackon_timer()
complete.After deleting the
this.add_ref()
,on_timer()
will not excute afterperf_counter_number_percentile_atomic
is released because the~perf_counter_number_percentile_atomic(void) { _timer->cancel(); }
will cancel the timer task. So we don't need worry about the case that using the released object.Change & Potential problem
In the old version, after the thread
perf_counter_number_percentile_atomic
is in is terminated, the timer won’t stop until the timer occurs error (for example, being canceled).In this PR, it will stop the timer task after the thread
perf_counter_number_percentile_atomic
is in is terminated, we need consider whether this change haves an effect on the result of timer task forcalc(ctx)
(in line 420).