Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dangling pointer in IndependentFlattener
IndependentFlattener keeps a raw_ptr to MetricsLog. For it not to become dangling, the MetricsLog needs to outlive the flattener, which is currently not the case. There are a few different problems, as explained below. In all cases, the IndependentFlattener is indirectly owned by a MetricsLogHistogramWriter. - SnapshotUnloggedSamplesAndFinalizeLog( MetricsLogHistogramWriter* log_histogram_writer, std::unique_ptr<MetricsLog> log, ...) This is problematic from an interface standpoint already, since the log is destroyed at the end of the function's scope, while the unowned log_histogram_writer is kept alive (by whoever owns it on the caller side). - MetricsService::SnapshotDeltasAndFinalizeLog( std::unique_ptr<MetricsLogHistogramWriter> log_histogram_writer, std::unique_ptr<MetricsLog> log, ...) { ... return FinalizeLog(std::move(log), ...); } This is broken for a similar reason: As ownership is transferred to FinalizeLog(), log is destroyed when FinalizeLog() returns, but log_histogram_writer is only destroyed when SnapshotDeltasAndFinalizeLog() returns slightly afterwards. Both cases are fixed by resetting the MetricsLogHistogramWriter's flattener before FinalizeLog(). Fixed: 41485234 Change-Id: I60d13e8237d90a09b3cc1e82d43d6c3587610993 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5808942 Commit-Queue: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Cr-Commit-Position: refs/heads/main@{#1348776}
- Loading branch information