File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -295,9 +295,18 @@ namespace firebase {
295
295
// Free data structure allocated in SetOnCompletionCallback() and save
296
296
// a reference to the current data structure if specified.
297
297
private void SetCompletionData (System.IntPtr data) {
298
- ThrowIfDisposed ();
299
- SWIG_FreeCompletionData (callbackData);
300
- callbackData = data;
298
+ lock (FirebaseApp.disposeLock ) {
299
+ // The callback that was made could theoretically be triggered before this point,
300
+ // which would Dispose this object. In that case, we want to free the data we
301
+ // were given, since otherwise it would be leaked.
302
+ if (swigCPtr.Handle == System.IntPtr .Zero ) {
303
+ SWIG_FreeCompletionData (data);
304
+ } else {
305
+ // Free the old data, before saving the new data for deletion
306
+ SWIG_FreeCompletionData (callbackData);
307
+ callbackData = data;
308
+ }
309
+ }
301
310
}
302
311
303
312
// Handles the C++ callback, and calls the cached C# callback.
@@ -389,7 +398,7 @@ namespace firebase {
389
398
}
390
399
391
400
// Deallocate data allocated for the completion callback.
392
- void SWIG_FreeCompletionData (void *data) {
401
+ static void SWIG_FreeCompletionData (void *data) {
393
402
delete reinterpret_cast <CSNAME##CallbackData*>(data);
394
403
}
395
404
You can’t perform that action at this time.
0 commit comments