Skip to content

Commit 94580e9

Browse files
committed
Add checks on auth_data, because of DeleteInternal
The new logic of DeleteInternal means that all the auth functions need to handle that it has been deleted. Also update the Unity automated test, so that it works. Tested by: Ran the Unity automated test on Mac editor PiperOrigin-RevId: 238766343
1 parent c6a326f commit 94580e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

auth/src/auth.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,18 @@ Auth::~Auth() { DeleteInternal(); }
167167
// holds nothing but a pointer to AuthData, which never changes.
168168
// All User functions that require synchronization go through AuthData's mutex.
169169
User* Auth::current_user() {
170+
if (!auth_data_) return nullptr;
170171
MutexLock lock(auth_data_->future_impl.mutex());
171172
User* user =
172173
auth_data_->user_impl == nullptr ? nullptr : &auth_data_->current_user;
173174
return user;
174175
}
175176

176177
// Always non-nullptr since set in constructor.
177-
App& Auth::app() { return *auth_data_->app; }
178+
App& Auth::app() {
179+
FIREBASE_ASSERT(auth_data_ != nullptr);
180+
return *auth_data_->app;
181+
}
178182

179183
template <typename T>
180184
static bool PushBackIfMissing(const T& entry, std::vector<T>* v) {
@@ -205,11 +209,13 @@ static void AddListener(T listener, std::vector<T>* listener_vector, Auth* auth,
205209
}
206210

207211
void Auth::AddAuthStateListener(AuthStateListener* listener) {
212+
if (!auth_data_) return;
208213
AddListener(listener, &auth_data_->listeners, this, &listener->auths_,
209214
&auth_data_->listeners_mutex);
210215
}
211216

212217
void Auth::AddIdTokenListener(IdTokenListener* listener) {
218+
if (!auth_data_) return;
213219
int listener_count = auth_data_->id_token_listeners.size();
214220
AddListener(listener, &auth_data_->id_token_listeners, this,
215221
&listener->auths_, &auth_data_->listeners_mutex);
@@ -253,11 +259,13 @@ static void RemoveListener(T listener, std::vector<T>* listener_vector,
253259
}
254260

255261
void Auth::RemoveAuthStateListener(AuthStateListener* listener) {
262+
if (!auth_data_) return;
256263
RemoveListener(listener, &auth_data_->listeners, this, &listener->auths_,
257264
&auth_data_->listeners_mutex);
258265
}
259266

260267
void Auth::RemoveIdTokenListener(IdTokenListener* listener) {
268+
if (!auth_data_) return;
261269
int listener_count = auth_data_->id_token_listeners.size();
262270
RemoveListener(listener, &auth_data_->id_token_listeners, this,
263271
&listener->auths_, &auth_data_->listeners_mutex);

0 commit comments

Comments
 (0)