From b7950e875f91cdc4b0c50d6106f138ae5b438e92 Mon Sep 17 00:00:00 2001 From: ChangGyu Choi Date: Thu, 12 Oct 2023 09:13:23 +0900 Subject: [PATCH] [Tdbc] Fix UpdateHookCallback released issue (#5528) The issue is that if you don't keep a reference to the UpdateHookCallback, it may be garbage collected before it is used. UpdateHookCallback should be referenced during used this. Signed-off-by: Changgyu Choi Co-authored-by: pjh9216 --- .../Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs b/src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs index b1463f6..5518e21 100644 --- a/src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs +++ b/src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs @@ -28,7 +28,7 @@ namespace Tizen.Data.Tdbc.Driver.Sqlite private bool disposedValue; private readonly object _lock = new object(); private EventHandler _recordChanged; - + private Interop.Sqlite.UpdateHookCallback _hook; static Connection() { @@ -70,6 +70,7 @@ namespace Tizen.Data.Tdbc.Driver.Sqlite Interop.Sqlite.UpdateHook(_db, null, IntPtr.Zero); Interop.Sqlite.Close(_db); _opened = false; + _hook = null; } } @@ -154,7 +155,12 @@ namespace Tizen.Data.Tdbc.Driver.Sqlite if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_OK) throw new InvalidOperationException("code:" + ret); - Interop.Sqlite.UpdateHook(_db, UpdateHookCallback, IntPtr.Zero); + if (_hook == null) + { + _hook = new Interop.Sqlite.UpdateHookCallback(UpdateHookCallback); + } + + Interop.Sqlite.UpdateHook(_db, _hook, IntPtr.Zero); _opened = true; } -- 2.7.4