Skip to content

Commit

Permalink
Duplicating fix for memory corruption with extra scopes to the native…
Browse files Browse the repository at this point in the history
… plugin.

Change-Id: I70cc91df221bbb5cbc0086045d00a1e9ce9bc1f3
  • Loading branch information
johnb003 committed Mar 21, 2018
1 parent 2276051 commit 9faa90f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
22 changes: 8 additions & 14 deletions staging/native/src/android/google_signin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ void GoogleSignIn::GoogleSignInImpl::Configure(
delete current_configuration_;
current_configuration_ = new Configuration(configuration);

if (configuration.web_client_id) {
current_configuration_->web_client_id = strdup(configuration.web_client_id);
}

delete current_result_;
current_result_ = new GoogleSignInFuture();

Expand All @@ -241,26 +237,24 @@ void GoogleSignIn::GoogleSignInImpl::CallConfigure() {
return;
}
jstring j_web_client_id =
current_configuration_->web_client_id
? env->NewStringUTF(current_configuration_->web_client_id)
: nullptr;
current_configuration_->web_client_id.empty() ? nullptr
: env->NewStringUTF(current_configuration_->web_client_id.c_str());

jstring j_account_name =
current_configuration_->account_name
? env->NewStringUTF(current_configuration_->account_name)
: nullptr;
current_configuration_->account_name.empty() ? nullptr
: env->NewStringUTF(current_configuration_->account_name.c_str());

jobjectArray j_auth_scopes = nullptr;

if (current_configuration_->additional_scope_count > 0) {
if (current_configuration_->additional_scopes.size() > 0) {
jclass string_clazz = jni_.FindClass("java/lang/String");
j_auth_scopes = env->NewObjectArray(
current_configuration_->additional_scope_count, string_clazz, nullptr);
current_configuration_->additional_scopes.size(), string_clazz, nullptr);

for (int i = 0; i < current_configuration_->additional_scope_count; i++) {
for (int i = 0; i < current_configuration_->additional_scopes.size(); i++) {
env->SetObjectArrayElement(
j_auth_scopes, i,
env->NewStringUTF(current_configuration_->additional_scopes[i]));
env->NewStringUTF(current_configuration_->additional_scopes[i].c_str()));
}
env->DeleteLocalRef(string_clazz);
}
Expand Down
9 changes: 6 additions & 3 deletions staging/native/src/include/google_signin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#ifndef GOOGLE_SIGNIN_GOOGLESIGNIN_H // NOLINT
#define GOOGLE_SIGNIN_GOOGLESIGNIN_H

#include <string>
#include <vector>

#include "future.h" // NOLINT
#include "google_signin_user.h" // NOLINT

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

Configuration(Configuration const &copy) = default;
Expand Down

0 comments on commit 9faa90f

Please sign in to comment.