File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ namespace Firebase.Messaging {
2222/// implementation.
2323public sealed class AndroidNotificationParams {
2424 internal static AndroidNotificationParams FromInternal ( AndroidNotificationParamsInternal other ) {
25+ if ( other == null ) return null ;
26+
2527 AndroidNotificationParams android = new AndroidNotificationParams ( ) ;
2628 android . ChannelId = other . channel_id ;
2729 return android ;
@@ -45,6 +47,8 @@ public void Dispose(bool disposing) { }
4547/// library.
4648public sealed class FirebaseNotification {
4749 internal static FirebaseNotification FromInternal ( FirebaseNotificationInternal other ) {
50+ if ( other == null ) return null ;
51+
4852 FirebaseNotification notification = new FirebaseNotification ( ) ;
4953 notification . Android = AndroidNotificationParams . FromInternal ( other . android ) ;
5054 notification . Badge = other . badge ;
Original file line number Diff line number Diff line change @@ -316,18 +316,22 @@ void SendPendingEvents() {
316316 // messageReceivedDelegate.
317317 [MonoPInvokeCallback(typeof(MessageReceivedDelegate))]
318318 private static int MessageReceivedDelegateMethod (System.IntPtr message) {
319+ int tookOwnership = 0 ;
319320 return ExceptionAggregator.Wrap (() => {
320321 // Use a local copy so another thread cannot unset this before we use it.
321322 var handler = FirebaseMessagingInternal.MessageReceivedInternal ;
322323 if (handler != null) {
324+ // Take ownership, and track it so that the caller of this knows, even
325+ // if an exception is thrown, since the C# object will still delete it.
323326 FirebaseMessageInternal messageInternal = new FirebaseMessageInternal (message, true );
327+ tookOwnership = 1 ;
324328 handler (null, new Firebase.Messaging .MessageReceivedEventArgs (
325329 FirebaseMessage.FromInternal (messageInternal)));
326330 messageInternal.Dispose ();
327331 return 1 ;
328332 }
329333 return 0 ;
330- }, 0 );
334+ }, tookOwnership );
331335 }
332336
333337 // Called from ListenerImpl::TokenReceived() via the
You can’t perform that action at this time.
0 commit comments