Skip to content

Commit 7913774

Browse files
chkuang-ga-maurice
authored andcommitted
Prevent the race condition between AppGetOrCreateInstance and AppReleaseReference
This potentially fix b/121161177 which crash at callback::Terminate(). Also do nullptr check in callback::Terminate() to make it a bit more durable. The result of the race is that the developer or any C# module may get a FirebaseApp through FirebaseApp.DefaultInstance or FirebaseApp.GetInstance() which is pointing to a C++ App scheduled to be deleted and result in double deletion to the same C++ App. PiperOrigin-RevId: 251735913
1 parent cec32ee commit 7913774

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/src/callback.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ void Terminate(bool flush_all) {
230230
// the outstanding number of items in the queue. In particular,
231231
// PollDispatcher() could be executing at this point since g_callback_mutex
232232
// isn't held by the ref count is > 0 for the duration of the function.
233-
if (flush_all) ref_count += g_callback_dispatcher->FlushCallbacks();
233+
if (flush_all && g_callback_dispatcher) {
234+
ref_count += g_callback_dispatcher->FlushCallbacks();
235+
}
234236
Terminate(ref_count);
235237
}
236238

0 commit comments

Comments
 (0)