cashew: fix assertion failure in ProcfsByteCounter dtor
In ProcfsByteCounter, OnStatsUpdate invokes the delegate's
OnByteCounterUpdate callback. It's possible for the byte counter to be
deleted before this callback returns.
This CL fixes two issues related to this possible deletion:
1) ReadStats calls OnStatsUpdate before calling CloseProcNetDev. If the
counter is deleted before OnStatsUpdate returns, then there is an
assertion failure within the dtor because /proc/net/dev is still open.
This CL ensures that CloseProcNetDev is called before OnStatsUpdate to
prevent this assertion failure.
2) OnStatsUpdate updates baseline_stats_ after invoking the delegate's
OnByteCounterUpdate callback. If the counter is deleted during the
callback, accessing this member variable afterwards results in undefined
behavior. This CL changes OnStatsUpdate to update baseline_stats_
earlier before invoking the delegate's callback.
BUG=chromium-os:17997
TEST=unit tests and manual testing on device
Change-Id: I113350a9bfccd4d5e2601accc992ce656e79adf2
Reviewed-on: http://gerrit.chromium.org/gerrit/4548
Tested-by: Vince Laviano <vlaviano@chromium.org>
Reviewed-by: Jason Glasgow <jglasgow@chromium.org>
1 file changed