Skip to content

Commit

Permalink
[Tizen.Core] Fix double free issues (Samsung#6335)
Browse files Browse the repository at this point in the history
* [Tizen.Core] Fix double free issues

The received object in the callback function should not be released.

Signed-off-by: Hwankyu Jhun <[email protected]>

* Prevent double free using an internal property

Signed-off-by: Hwankyu Jhun <[email protected]>

---------

Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored and bshsqa committed Sep 25, 2024
1 parent 8fe84ca commit bb6075f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Tizen.Core/Tizen.Core/ChannelObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public ChannelObject(int id, object data)
Id = id;
Data = data;
IsUsed = false;
IsDestroyable = true;
}

internal ChannelObject(IntPtr handle)
{
_handle = handle;
IsUsed = false;
IsDestroyable = true;
}

/// <summary>
Expand Down Expand Up @@ -128,6 +130,8 @@ public string Sender {
}
}

internal bool IsDestroyable { set; get; }

internal bool IsUsed { set; get; }

internal IntPtr Handle { get { return _handle; } }
Expand All @@ -152,7 +156,10 @@ protected virtual void Dispose(bool disposing)
_dataMap.TryRemove(id, out var data);
}

Interop.LibTizenCore.TizenCoreChannel.ObjectDestroy(_handle);
if (IsDestroyable)
{
Interop.LibTizenCore.TizenCoreChannel.ObjectDestroy(_handle);
}
_handle = IntPtr.Zero;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Tizen.Core/Tizen.Core/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private bool EventHandlerCallback(IntPtr eventData, IntPtr userData)
using (var eventObject = new EventObject(eventData))
{
EventReceived?.Invoke(this, new EventReceivedEventArgs(eventObject));
eventObject.Handle = IntPtr.Zero;
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/Tizen.Core/Tizen.Core/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ private static void NativeChannelReceiveCallback(IntPtr nativeObject, IntPtr use
{
var eventArgs = new ChannelReceivedEventArgs(channelObject);
receiver.InvokeEventHandler(null, eventArgs);
channelObject.IsDestroyable = false;
}
}
}
Expand Down

0 comments on commit bb6075f

Please sign in to comment.