Skip to content

Commit 7bf0359

Browse files
committed
Fix clang-tidy warning
The combination of `std::move` on a `std::optional` value in `CF_EXPECT` was flagging as a potential memory leak. This version avoids the `std::optional` wrapper on the values.
1 parent d6816da commit 7bf0359

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

base/cvd/cuttlefish/host/libs/web/credential_source.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
#include <stddef.h>
1919
#include <stdint.h>
2020

21-
#include <cstddef>
2221
#include <chrono>
22+
#include <cstddef>
2323
#include <memory>
2424
#include <mutex>
25-
#include <optional>
2625
#include <sstream>
2726
#include <string>
2827
#include <string_view>
@@ -203,9 +202,9 @@ Result<std::unique_ptr<RefreshTokenCredentialSource>>
203202
RefreshTokenCredentialSource::FromOauth2ClientFile(
204203
HttpClient& http_client, const std::string& oauth_contents) {
205204
if (absl::StartsWith(oauth_contents, "[OAuth2]")) { // .boto file
206-
std::optional<std::string> client_id;
207-
std::optional<std::string> client_secret;
208-
std::optional<std::string> refresh_token;
205+
std::string client_id = "";
206+
std::string client_secret = "";
207+
std::string refresh_token = "";
209208
auto lines = android::base::Tokenize(oauth_contents, "\n");
210209
for (auto line : lines) {
211210
std::string_view line_view = line;
@@ -226,11 +225,12 @@ RefreshTokenCredentialSource::FromOauth2ClientFile(
226225
continue;
227226
}
228227
}
228+
CF_EXPECT(!client_id.empty());
229+
CF_EXPECT(!client_secret.empty());
230+
CF_EXPECT(!refresh_token.empty());
229231
return std::unique_ptr<RefreshTokenCredentialSource>(
230-
new RefreshTokenCredentialSource(http_client,
231-
CF_EXPECT(std::move(client_id)),
232-
CF_EXPECT(std::move(client_secret)),
233-
CF_EXPECT(std::move(refresh_token))));
232+
new RefreshTokenCredentialSource(http_client, client_id, client_secret,
233+
refresh_token));
234234
}
235235
auto json = CF_EXPECT(ParseJson(oauth_contents));
236236
if (json.isMember("refresh_token")) {

0 commit comments

Comments
 (0)