Commit 0e68e5fc authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Fix use-after-move in //c/b/chromeos/net/network_diagnostics/

Fix use-after-move (potential) bugs found by the
"bugprone-use-after-move" clang-tidy check.

Bug: 1122844
Change-Id: Ife278a458c9151724a8426541063ae7d3261a49b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2555042
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Auto-Submit: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarKartik Hegde <khegde@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830610}
parent ae4f2afe
......@@ -67,6 +67,7 @@ void HasSecureWiFiConnectionRoutine::RunRoutine(
HasSecureWiFiConnectionRoutineCallback callback) {
if (!CanRun()) {
std::move(callback).Run(verdict(), std::move(problems_));
return;
}
routine_completed_callback_ = std::move(callback);
FetchActiveWiFiNetworks();
......
......@@ -43,10 +43,11 @@ void NetworkDiagnostics::BindReceiver(
void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) {
auto routine = std::make_unique<LanConnectivityRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<LanConnectivityRoutine> routine,
LanConnectivityCallback callback,
mojom::RoutineVerdict verdict) { std::move(callback).Run(verdict); },
......@@ -55,10 +56,11 @@ void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) {
void NetworkDiagnostics::SignalStrength(SignalStrengthCallback callback) {
auto routine = std::make_unique<SignalStrengthRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<SignalStrengthRoutine> routine,
SignalStrengthCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::SignalStrengthProblem>& problems) {
......@@ -71,10 +73,11 @@ void NetworkDiagnostics::GatewayCanBePinged(
GatewayCanBePingedCallback callback) {
auto routine =
std::make_unique<GatewayCanBePingedRoutine>(debug_daemon_client_);
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<GatewayCanBePingedRoutine> routine,
GatewayCanBePingedCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::GatewayCanBePingedProblem>& problems) {
......@@ -86,10 +89,11 @@ void NetworkDiagnostics::GatewayCanBePinged(
void NetworkDiagnostics::HasSecureWiFiConnection(
HasSecureWiFiConnectionCallback callback) {
auto routine = std::make_unique<HasSecureWiFiConnectionRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HasSecureWiFiConnectionRoutine> routine,
HasSecureWiFiConnectionCallback callback,
mojom::RoutineVerdict verdict,
......@@ -102,10 +106,11 @@ void NetworkDiagnostics::HasSecureWiFiConnection(
void NetworkDiagnostics::DnsResolverPresent(
DnsResolverPresentCallback callback) {
auto routine = std::make_unique<DnsResolverPresentRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsResolverPresentRoutine> routine,
DnsResolverPresentCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsResolverPresentProblem>& problems) {
......@@ -116,10 +121,11 @@ void NetworkDiagnostics::DnsResolverPresent(
void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) {
auto routine = std::make_unique<DnsLatencyRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsLatencyRoutine> routine,
DnsLatencyCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsLatencyProblem>& problems) {
......@@ -130,10 +136,11 @@ void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) {
void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) {
auto routine = std::make_unique<DnsResolutionRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsResolutionRoutine> routine,
DnsResolutionCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsResolutionProblem>& problems) {
......@@ -144,10 +151,11 @@ void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) {
void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) {
auto routine = std::make_unique<CaptivePortalRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<CaptivePortalRoutine> routine,
CaptivePortalCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::CaptivePortalProblem>& problems) {
......@@ -158,10 +166,11 @@ void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) {
void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) {
auto routine = std::make_unique<HttpFirewallRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpFirewallRoutine> routine,
HttpFirewallCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpFirewallProblem>& problems) {
......@@ -172,10 +181,11 @@ void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) {
void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) {
auto routine = std::make_unique<HttpsFirewallRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpsFirewallRoutine> routine,
HttpsFirewallCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpsFirewallProblem>& problems) {
......@@ -186,10 +196,11 @@ void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) {
void NetworkDiagnostics::HttpsLatency(HttpsLatencyCallback callback) {
auto routine = std::make_unique<HttpsLatencyRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce(
routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpsLatencyRoutine> routine,
HttpsLatencyCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpsLatencyProblem>& problems) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment