Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Dapper.AOT/Internal/AsyncCommandState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public virtual ValueTask DisposeAsync()

if (cmd is not null)
{
// match vanilla's teardown: release caller-supplied parameter objects
cmd.Parameters.Clear();
if (conn is not null && (_flags & FLAG_CLOSE_CONNECTION) != 0)
{
// need to close the connection and dispose the command
Expand Down Expand Up @@ -178,7 +180,12 @@ public virtual void Dispose()
{
var cmd = Command;
Command = null;
cmd?.Dispose();
if (cmd is not null)
{
// match vanilla's teardown: release caller-supplied parameter objects
cmd.Parameters.Clear();
cmd.Dispose();
}

var conn = connection;
connection = null;
Expand Down
7 changes: 6 additions & 1 deletion src/Dapper.AOT/Internal/SyncCommandState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public void Dispose()
{
var cmd = Command;
Command = null;
cmd?.Dispose();
if (cmd is not null)
{
// match vanilla's teardown: release caller-supplied parameter objects
cmd.Parameters.Clear();
cmd.Dispose();
}

var conn = connection;
connection = null;
Expand Down
9 changes: 8 additions & 1 deletion src/Dapper.AOT/UnifiedCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,14 @@ private DbCommand UnsafeWithCommandForParameters()

internal void Cleanup()
{
dbCommand?.Dispose();
if (dbCommand is not null)
{
// match vanilla Dapper's teardown: a parameter object the caller supplied
// (ICustomQueryParameter, DynamicParameters.Add(DbParameter), etc) must not
// stay owned by a dead command's collection, or it cannot be reused
dbCommand.Parameters.Clear();
dbCommand.Dispose();
}
#if NET6_0_OR_GREATER
batch?.Dispose();
#endif
Expand Down
Loading