Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Possible leak when scheduling local iOS Notifications

Discussion in 'Scripting' started by vitaliano_fanatee, May 25, 2021.

  1. vitaliano_fanatee

    vitaliano_fanatee

    Joined:
    Oct 9, 2020
    Posts:
    37
    I was looking into the file, com.unity.mobile.notifications@1.3.2\Runtime\iOS\iOSNotificationsWrapper.cs, and I think that there is a missing FreeHGlobal at the end of the ScheduleLocalNotification method.

    You can check it below:
    Code (CSharp):
    1.         public static void ScheduleLocalNotification(iOSNotificationData data)
    2.         {
    3. #if UNITY_IOS && !UNITY_EDITOR
    4.             IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(data));
    5.             Marshal.StructureToPtr(data, ptr, false);
    6.  
    7.             _ScheduleLocalNotification(ptr);
    8. #endif
    9.         }
    Is there a reason to allocating the iOSNotificationData struct and not freeing it afterwards?

    My best regards,
    Vitaliano