Skip to content

Commit

Permalink
[Tdbc] Fix UpdateHookCallback released issue (Samsung#5528)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: pjh9216 <[email protected]>
  • Loading branch information
upple and pjh9216 authored Oct 12, 2023
1 parent 781fa26 commit b7950e8
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class Connection : IConnection
private bool disposedValue;
private readonly object _lock = new object();
private EventHandler<RecordChangedEventArgs> _recordChanged;

private Interop.Sqlite.UpdateHookCallback _hook;

static Connection()
{
Expand Down Expand Up @@ -70,6 +70,7 @@ public void Close()
Interop.Sqlite.UpdateHook(_db, null, IntPtr.Zero);
Interop.Sqlite.Close(_db);
_opened = false;
_hook = null;
}
}

Expand Down Expand Up @@ -154,7 +155,12 @@ public void Open(Uri uri)
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;
}

Expand Down

0 comments on commit b7950e8

Please sign in to comment.