Prevent the race condition between AppGetOrCreateInstance and AppReleaseReference
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

firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk,firebase/firebase-cpp-sdk