Skip to content

Commit 9faa90f

Browse files
committed
Duplicating fix for memory corruption with extra scopes to the native plugin.
Change-Id: I70cc91df221bbb5cbc0086045d00a1e9ce9bc1f3
1 parent 2276051 commit 9faa90f

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

staging/native/src/android/google_signin.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ void GoogleSignIn::GoogleSignInImpl::Configure(
223223
delete current_configuration_;
224224
current_configuration_ = new Configuration(configuration);
225225

226-
if (configuration.web_client_id) {
227-
current_configuration_->web_client_id = strdup(configuration.web_client_id);
228-
}
229-
230226
delete current_result_;
231227
current_result_ = new GoogleSignInFuture();
232228

@@ -241,26 +237,24 @@ void GoogleSignIn::GoogleSignInImpl::CallConfigure() {
241237
return;
242238
}
243239
jstring j_web_client_id =
244-
current_configuration_->web_client_id
245-
? env->NewStringUTF(current_configuration_->web_client_id)
246-
: nullptr;
240+
current_configuration_->web_client_id.empty() ? nullptr
241+
: env->NewStringUTF(current_configuration_->web_client_id.c_str());
247242

248243
jstring j_account_name =
249-
current_configuration_->account_name
250-
? env->NewStringUTF(current_configuration_->account_name)
251-
: nullptr;
244+
current_configuration_->account_name.empty() ? nullptr
245+
: env->NewStringUTF(current_configuration_->account_name.c_str());
252246

253247
jobjectArray j_auth_scopes = nullptr;
254248

255-
if (current_configuration_->additional_scope_count > 0) {
249+
if (current_configuration_->additional_scopes.size() > 0) {
256250
jclass string_clazz = jni_.FindClass("java/lang/String");
257251
j_auth_scopes = env->NewObjectArray(
258-
current_configuration_->additional_scope_count, string_clazz, nullptr);
252+
current_configuration_->additional_scopes.size(), string_clazz, nullptr);
259253

260-
for (int i = 0; i < current_configuration_->additional_scope_count; i++) {
254+
for (int i = 0; i < current_configuration_->additional_scopes.size(); i++) {
261255
env->SetObjectArrayElement(
262256
j_auth_scopes, i,
263-
env->NewStringUTF(current_configuration_->additional_scopes[i]));
257+
env->NewStringUTF(current_configuration_->additional_scopes[i].c_str()));
264258
}
265259
env->DeleteLocalRef(string_clazz);
266260
}

staging/native/src/include/google_signin.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef GOOGLE_SIGNIN_GOOGLESIGNIN_H // NOLINT
1616
#define GOOGLE_SIGNIN_GOOGLESIGNIN_H
1717

18+
#include <string>
19+
#include <vector>
20+
1821
#include "future.h" // NOLINT
1922
#include "google_signin_user.h" // NOLINT
2023

@@ -91,7 +94,7 @@ class GoogleSignIn {
9194
/// games signing only works on Android.
9295
bool use_game_signin;
9396
/// Web client id associated with this app.
94-
const char *web_client_id;
97+
std::string web_client_id;
9598
/// true for getting an auth code when authenticating.
9699
/// Note: This may trigger re-consent on iOS. Ideally, this
97100
/// is set to true once, and the result sent to the server where the
@@ -108,9 +111,9 @@ class GoogleSignIn {
108111
/// recommended for VR applications.
109112
bool hide_ui_popups;
110113
/// account name to use when authenticating, null indicates use default.
111-
const char *account_name;
114+
std::string account_name;
112115
/// additional scopes to request, requires consent.
113-
const char **additional_scopes;
116+
std::vector<std::string> additional_scopes;
114117
int additional_scope_count;
115118

116119
Configuration(Configuration const &copy) = default;

0 commit comments

Comments
 (0)