diff options
| author | 2018-09-17 14:28:58 -0400 | |
|---|---|---|
| committer | 2018-10-02 15:30:48 +0200 | |
| commit | 62f9409ba3e114b40b6923808290c02bf5af3d2c (patch) | |
| tree | b628db116034f811d0b55b8d8384bd704f80aa18 /src/web_service/web_backend.cpp | |
| parent | Address more review comments (diff) | |
| download | yuzu-62f9409ba3e114b40b6923808290c02bf5af3d2c.tar.gz yuzu-62f9409ba3e114b40b6923808290c02bf5af3d2c.tar.xz yuzu-62f9409ba3e114b40b6923808290c02bf5af3d2c.zip | |
web_backend: protect jwt cache with a mutex
Diffstat (limited to 'src/web_service/web_backend.cpp')
| -rw-r--r-- | src/web_service/web_backend.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 3a3f44dc2..5df4df5eb 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp | |||
| @@ -24,6 +24,7 @@ Client::JWTCache Client::jwt_cache{}; | |||
| 24 | 24 | ||
| 25 | Client::Client(const std::string& host, const std::string& username, const std::string& token) | 25 | Client::Client(const std::string& host, const std::string& username, const std::string& token) |
| 26 | : host(host), username(username), token(token) { | 26 | : host(host), username(username), token(token) { |
| 27 | std::lock_guard<std::mutex> lock(jwt_cache.mutex); | ||
| 27 | if (username == jwt_cache.username && token == jwt_cache.token) { | 28 | if (username == jwt_cache.username && token == jwt_cache.token) { |
| 28 | jwt = jwt_cache.jwt; | 29 | jwt = jwt_cache.jwt; |
| 29 | } | 30 | } |
| @@ -116,6 +117,7 @@ void Client::UpdateJWT() { | |||
| 116 | if (result.result_code != Common::WebResult::Code::Success) { | 117 | if (result.result_code != Common::WebResult::Code::Success) { |
| 117 | LOG_ERROR(WebService, "UpdateJWT failed"); | 118 | LOG_ERROR(WebService, "UpdateJWT failed"); |
| 118 | } else { | 119 | } else { |
| 120 | std::lock_guard<std::mutex> lock(jwt_cache.mutex); | ||
| 119 | jwt_cache.username = username; | 121 | jwt_cache.username = username; |
| 120 | jwt_cache.token = token; | 122 | jwt_cache.token = token; |
| 121 | jwt_cache.jwt = jwt = result.returned_data; | 123 | jwt_cache.jwt = jwt = result.returned_data; |