@@ -69,7 +69,7 @@ public:
6969 // OnMessage() callback in this class. SWIGSTDCALL is used here as C#
7070 // delegates *must* be called using the stdcall calling convention rather
7171 // than whatever the compiler defines.
72- typedef int (SWIGSTDCALL *MessageReceivedCallback)(void * message);
72+ typedef bool (SWIGSTDCALL *MessageReceivedCallback)(void * message);
7373 // Function which is used to reference a C# delegate which is called from
7474 // OnTokenReceived() callback in this class. SWIGSTDCALL is used here as C#
7575 // delegates *must* be called using the stdcall calling convention rather
@@ -250,7 +250,7 @@ void SendPendingEvents() {
250250 // Listener.TokenReceivedDelegateMethod respectively.
251251 internal class Listener : System.IDisposable {
252252 // Delegate called from ListenerImpl::MessageReceivedCallback().
253- internal delegate int MessageReceivedDelegate (System.IntPtr message);
253+ internal delegate bool MessageReceivedDelegate (System.IntPtr message);
254254 // Delegate called from ListenerImpl::TokenReceivedCallback().
255255 internal delegate void TokenReceivedDelegate (string token);
256256
@@ -315,19 +315,23 @@ void SendPendingEvents() {
315315 // Called from ListenerImpl::MessageReceived() via the
316316 // messageReceivedDelegate.
317317 [MonoPInvokeCallback(typeof (MessageReceivedDelegate))]
318- private static int MessageReceivedDelegateMethod (System.IntPtr message) {
318+ private static bool MessageReceivedDelegateMethod (System.IntPtr message) {
319+ bool tookOwnership = false ;
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 = true ;
324328 handler (null, new Firebase.Messaging .MessageReceivedEventArgs (
325329 FirebaseMessage.FromInternal (messageInternal)));
326330 messageInternal.Dispose ();
327- return 1 ;
331+ return true ;
328332 }
329- return 0 ;
330- }, 0 );
333+ return false ;
334+ }, tookOwnership );
331335 }
332336
333337 // Called from ListenerImpl::TokenReceived() via the
0 commit comments