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( ...@@ -67,6 +67,7 @@ void HasSecureWiFiConnectionRoutine::RunRoutine(
HasSecureWiFiConnectionRoutineCallback callback) { HasSecureWiFiConnectionRoutineCallback callback) {
if (!CanRun()) { if (!CanRun()) {
std::move(callback).Run(verdict(), std::move(problems_)); std::move(callback).Run(verdict(), std::move(problems_));
return;
} }
routine_completed_callback_ = std::move(callback); routine_completed_callback_ = std::move(callback);
FetchActiveWiFiNetworks(); FetchActiveWiFiNetworks();
......
...@@ -43,10 +43,11 @@ void NetworkDiagnostics::BindReceiver( ...@@ -43,10 +43,11 @@ void NetworkDiagnostics::BindReceiver(
void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) { void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) {
auto routine = std::make_unique<LanConnectivityRoutine>(); auto routine = std::make_unique<LanConnectivityRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<LanConnectivityRoutine> routine, [](std::unique_ptr<LanConnectivityRoutine> routine,
LanConnectivityCallback callback, LanConnectivityCallback callback,
mojom::RoutineVerdict verdict) { std::move(callback).Run(verdict); }, mojom::RoutineVerdict verdict) { std::move(callback).Run(verdict); },
...@@ -55,10 +56,11 @@ void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) { ...@@ -55,10 +56,11 @@ void NetworkDiagnostics::LanConnectivity(LanConnectivityCallback callback) {
void NetworkDiagnostics::SignalStrength(SignalStrengthCallback callback) { void NetworkDiagnostics::SignalStrength(SignalStrengthCallback callback) {
auto routine = std::make_unique<SignalStrengthRoutine>(); auto routine = std::make_unique<SignalStrengthRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<SignalStrengthRoutine> routine, [](std::unique_ptr<SignalStrengthRoutine> routine,
SignalStrengthCallback callback, mojom::RoutineVerdict verdict, SignalStrengthCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::SignalStrengthProblem>& problems) { const std::vector<mojom::SignalStrengthProblem>& problems) {
...@@ -71,10 +73,11 @@ void NetworkDiagnostics::GatewayCanBePinged( ...@@ -71,10 +73,11 @@ void NetworkDiagnostics::GatewayCanBePinged(
GatewayCanBePingedCallback callback) { GatewayCanBePingedCallback callback) {
auto routine = auto routine =
std::make_unique<GatewayCanBePingedRoutine>(debug_daemon_client_); std::make_unique<GatewayCanBePingedRoutine>(debug_daemon_client_);
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<GatewayCanBePingedRoutine> routine, [](std::unique_ptr<GatewayCanBePingedRoutine> routine,
GatewayCanBePingedCallback callback, mojom::RoutineVerdict verdict, GatewayCanBePingedCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::GatewayCanBePingedProblem>& problems) { const std::vector<mojom::GatewayCanBePingedProblem>& problems) {
...@@ -86,10 +89,11 @@ void NetworkDiagnostics::GatewayCanBePinged( ...@@ -86,10 +89,11 @@ void NetworkDiagnostics::GatewayCanBePinged(
void NetworkDiagnostics::HasSecureWiFiConnection( void NetworkDiagnostics::HasSecureWiFiConnection(
HasSecureWiFiConnectionCallback callback) { HasSecureWiFiConnectionCallback callback) {
auto routine = std::make_unique<HasSecureWiFiConnectionRoutine>(); auto routine = std::make_unique<HasSecureWiFiConnectionRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HasSecureWiFiConnectionRoutine> routine, [](std::unique_ptr<HasSecureWiFiConnectionRoutine> routine,
HasSecureWiFiConnectionCallback callback, HasSecureWiFiConnectionCallback callback,
mojom::RoutineVerdict verdict, mojom::RoutineVerdict verdict,
...@@ -102,10 +106,11 @@ void NetworkDiagnostics::HasSecureWiFiConnection( ...@@ -102,10 +106,11 @@ void NetworkDiagnostics::HasSecureWiFiConnection(
void NetworkDiagnostics::DnsResolverPresent( void NetworkDiagnostics::DnsResolverPresent(
DnsResolverPresentCallback callback) { DnsResolverPresentCallback callback) {
auto routine = std::make_unique<DnsResolverPresentRoutine>(); auto routine = std::make_unique<DnsResolverPresentRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsResolverPresentRoutine> routine, [](std::unique_ptr<DnsResolverPresentRoutine> routine,
DnsResolverPresentCallback callback, mojom::RoutineVerdict verdict, DnsResolverPresentCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsResolverPresentProblem>& problems) { const std::vector<mojom::DnsResolverPresentProblem>& problems) {
...@@ -116,10 +121,11 @@ void NetworkDiagnostics::DnsResolverPresent( ...@@ -116,10 +121,11 @@ void NetworkDiagnostics::DnsResolverPresent(
void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) { void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) {
auto routine = std::make_unique<DnsLatencyRoutine>(); auto routine = std::make_unique<DnsLatencyRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsLatencyRoutine> routine, [](std::unique_ptr<DnsLatencyRoutine> routine,
DnsLatencyCallback callback, mojom::RoutineVerdict verdict, DnsLatencyCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsLatencyProblem>& problems) { const std::vector<mojom::DnsLatencyProblem>& problems) {
...@@ -130,10 +136,11 @@ void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) { ...@@ -130,10 +136,11 @@ void NetworkDiagnostics::DnsLatency(DnsLatencyCallback callback) {
void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) { void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) {
auto routine = std::make_unique<DnsResolutionRoutine>(); auto routine = std::make_unique<DnsResolutionRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<DnsResolutionRoutine> routine, [](std::unique_ptr<DnsResolutionRoutine> routine,
DnsResolutionCallback callback, mojom::RoutineVerdict verdict, DnsResolutionCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::DnsResolutionProblem>& problems) { const std::vector<mojom::DnsResolutionProblem>& problems) {
...@@ -144,10 +151,11 @@ void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) { ...@@ -144,10 +151,11 @@ void NetworkDiagnostics::DnsResolution(DnsResolutionCallback callback) {
void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) { void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) {
auto routine = std::make_unique<CaptivePortalRoutine>(); auto routine = std::make_unique<CaptivePortalRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<CaptivePortalRoutine> routine, [](std::unique_ptr<CaptivePortalRoutine> routine,
CaptivePortalCallback callback, mojom::RoutineVerdict verdict, CaptivePortalCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::CaptivePortalProblem>& problems) { const std::vector<mojom::CaptivePortalProblem>& problems) {
...@@ -158,10 +166,11 @@ void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) { ...@@ -158,10 +166,11 @@ void NetworkDiagnostics::CaptivePortal(CaptivePortalCallback callback) {
void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) { void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) {
auto routine = std::make_unique<HttpFirewallRoutine>(); auto routine = std::make_unique<HttpFirewallRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpFirewallRoutine> routine, [](std::unique_ptr<HttpFirewallRoutine> routine,
HttpFirewallCallback callback, mojom::RoutineVerdict verdict, HttpFirewallCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpFirewallProblem>& problems) { const std::vector<mojom::HttpFirewallProblem>& problems) {
...@@ -172,10 +181,11 @@ void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) { ...@@ -172,10 +181,11 @@ void NetworkDiagnostics::HttpFirewall(HttpFirewallCallback callback) {
void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) { void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) {
auto routine = std::make_unique<HttpsFirewallRoutine>(); auto routine = std::make_unique<HttpsFirewallRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpsFirewallRoutine> routine, [](std::unique_ptr<HttpsFirewallRoutine> routine,
HttpsFirewallCallback callback, mojom::RoutineVerdict verdict, HttpsFirewallCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpsFirewallProblem>& problems) { const std::vector<mojom::HttpsFirewallProblem>& problems) {
...@@ -186,10 +196,11 @@ void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) { ...@@ -186,10 +196,11 @@ void NetworkDiagnostics::HttpsFirewall(HttpsFirewallCallback callback) {
void NetworkDiagnostics::HttpsLatency(HttpsLatencyCallback callback) { void NetworkDiagnostics::HttpsLatency(HttpsLatencyCallback callback) {
auto routine = std::make_unique<HttpsLatencyRoutine>(); auto routine = std::make_unique<HttpsLatencyRoutine>();
auto* const routine_ptr = routine.get();
// RunRoutine() takes a lambda callback that takes ownership of the routine. // RunRoutine() takes a lambda callback that takes ownership of the routine.
// This ensures that the routine stays alive when it makes asynchronous mojo // This ensures that the routine stays alive when it makes asynchronous mojo
// calls. The routine will be destroyed when the lambda exits. // calls. The routine will be destroyed when the lambda exits.
routine->RunRoutine(base::BindOnce( routine_ptr->RunRoutine(base::BindOnce(
[](std::unique_ptr<HttpsLatencyRoutine> routine, [](std::unique_ptr<HttpsLatencyRoutine> routine,
HttpsLatencyCallback callback, mojom::RoutineVerdict verdict, HttpsLatencyCallback callback, mojom::RoutineVerdict verdict,
const std::vector<mojom::HttpsLatencyProblem>& problems) { 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