From: Hyunho Kang Date: Wed, 15 Nov 2017 08:05:02 +0000 (+0900) Subject: [WidgetControl]Fix callback memory freed bug X-Git-Tag: 4.0.1-preview1-00027^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F161179%2F1;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [WidgetControl]Fix callback memory freed bug Change-Id: Ib380538352686ce1e4d50ebc810a28024913d6bf Signed-off-by: Hyunho Kang (cherry picked from commit 92d4fa62d90b55e7b6d487c3c5aa764e1c224bf5) --- diff --git a/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs b/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs index 995814c..3be41ed 100755 --- a/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs +++ b/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs @@ -56,7 +56,7 @@ internal static partial class Interop internal delegate void InstanceCallback(string widgetId, string instanceId, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void LifecycleCallback(string widgetId, LifecycleEvent e, string instanceId, IntPtr userData); + internal delegate int LifecycleCallback(string widgetId, LifecycleEvent e, string instanceId, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void WidgetListCallback(string widgetId, int isPrime, IntPtr userData); diff --git a/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs b/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs index ff6906a..fe4a3d5 100755 --- a/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs +++ b/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs @@ -28,6 +28,7 @@ namespace Tizen.Applications public class WidgetControl : IDisposable { private const string LogTag = "Tizen.Applications.WidgetControl"; + private static Interop.WidgetService.LifecycleCallback _onLifecycleCallback; /// /// Class for the widget instance. /// @@ -616,8 +617,10 @@ namespace Tizen.Applications if (s_lifecycleEventRefCnt[Id] == 0) { - Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, OnLifecycleEvent, IntPtr.Zero); + if (_onLifecycleCallback == null) + _onLifecycleCallback = new Interop.WidgetService.LifecycleCallback(OnLifecycleEvent); + Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, _onLifecycleCallback, IntPtr.Zero); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: @@ -630,6 +633,7 @@ namespace Tizen.Applications s_lifecycleEventRefCnt[Id]++; s_eventObjects.Add(this); + Log.Debug(LogTag, "register lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]"); } private void UnregisterLifecycleEvent() @@ -658,14 +662,17 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.NotExist: throw new InvalidOperationException("Event handler is not exist"); } + _onLifecycleCallback = null; } s_eventObjects.Remove(this); s_lifecycleEventRefCnt[Id]--; + Log.Debug(LogTag, "unregister lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]"); } - private static void OnLifecycleEvent(string widgetId, Interop.WidgetService.LifecycleEvent e, string instanceId, IntPtr userData) + private static int OnLifecycleEvent(string widgetId, Interop.WidgetService.LifecycleEvent e, string instanceId, IntPtr userData) { + Log.Debug(LogTag, "Lifecycle event : " + instanceId + " [" + e + "]"); switch (e) { case Interop.WidgetService.LifecycleEvent.Created: @@ -728,6 +735,7 @@ namespace Tizen.Applications } break; } + return 0; } }