Harden disposal paths and test project metadata

This commit is contained in:
root
2026-02-23 21:31:07 +01:00
parent a2fd695738
commit 03b7d06a14
10 changed files with 192 additions and 122 deletions

View File

@@ -13,6 +13,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>

View File

@@ -964,6 +964,9 @@ namespace DynamORM.Builders.Implementation
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public virtual void Dispose() public virtual void Dispose()
{ {
if (IsDisposed)
return;
IsDisposed = true; IsDisposed = true;
if (Database != null) if (Database != null)

View File

@@ -32,6 +32,7 @@ namespace DynamORM
private List<Data> _data = new List<Data>(); private List<Data> _data = new List<Data>();
private int _currentDataPosition = 0; private int _currentDataPosition = 0;
private bool _isDisposed;
private DynamicCachedReader() private DynamicCachedReader()
{ {
@@ -445,12 +446,28 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
if (_isDisposed)
return;
_isDisposed = true;
IsClosed = true;
if (_data == null)
return;
foreach (var data in _data) foreach (var data in _data)
{ {
data._names.Clear(); if (data == null)
data._types.Clear(); continue;
data._cache.Clear();
data._schema.Dispose(); if (data._names != null)
data._names.Clear();
if (data._types != null)
data._types.Clear();
if (data._cache != null)
data._cache.Clear();
if (data._schema != null)
data._schema.Dispose();
} }
_data.Clear(); _data.Clear();

View File

@@ -264,18 +264,31 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
lock (_db.SyncLock) if (IsDisposed)
return;
var db = _db;
if (db == null)
{ {
IsDisposed = true;
return;
}
lock (db.SyncLock)
{
if (IsDisposed)
return;
IsDisposed = true;
if (_con != null) if (_con != null)
{ {
List<IDbCommand> pool = _db.CommandsPool.TryGetValue(_con.Connection); List<IDbCommand> pool = db.CommandsPool.TryGetValue(_con.Connection);
if (pool != null && pool.Contains(this)) if (pool != null && pool.Contains(this))
pool.Remove(this); pool.Remove(this);
} }
IsDisposed = true;
if (_command != null) if (_command != null)
{ {
_command.Parameters.Clear(); _command.Parameters.Clear();
@@ -283,6 +296,9 @@ namespace DynamORM
_command.Dispose(); _command.Dispose();
_command = null; _command = null;
} }
_con = null;
_db = null;
} }
} }

View File

@@ -165,7 +165,15 @@ namespace DynamORM
/// releasing, or resetting unmanaged resources.</summary> /// releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
_db.Close(Connection); if (IsDisposed)
return;
var db = _db;
if (db != null && Connection != null)
db.Close(Connection);
Connection = null;
_db = null;
IsDisposed = true; IsDisposed = true;
} }

View File

@@ -2010,6 +2010,9 @@ namespace DynamORM
/// releasing, or resetting unmanaged resources.</summary> /// releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
if (IsDisposed)
return;
#if !DYNAMORM_OMMIT_OLDSYNTAX #if !DYNAMORM_OMMIT_OLDSYNTAX
List<DynamicTable> tables = TablesCache.Values.ToList(); List<DynamicTable> tables = TablesCache.Values.ToList();
TablesCache.Clear(); TablesCache.Clear();
@@ -2067,6 +2070,8 @@ namespace DynamORM
if (_proc != null) if (_proc != null)
_proc.Dispose(); _proc.Dispose();
_proc = null;
_tempConn = null;
IsDisposed = true; IsDisposed = true;
} }

View File

@@ -55,6 +55,7 @@ namespace DynamORM
{ {
private DynamicDatabase _db; private DynamicDatabase _db;
private List<string> _prefixes; private List<string> _prefixes;
private bool _isDisposed;
internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null) internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null)
{ {
@@ -450,6 +451,12 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
if (_isDisposed)
return;
_isDisposed = true;
_db = null;
_prefixes = null;
} }
} }
} }

View File

@@ -954,6 +954,9 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
if (IsDisposed)
return;
// Lose reference but don't kill it. // Lose reference but don't kill it.
if (Database != null) if (Database != null)
{ {

View File

@@ -174,11 +174,18 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
if (_isDisposed)
return;
_isDisposed = true; _isDisposed = true;
Rollback(); Rollback();
if (_disposed != null) if (_disposed != null)
_disposed(); _disposed();
_disposed = null;
_con = null;
_db = null;
} }
/// <summary>Gets a value indicating whether this instance is disposed.</summary> /// <summary>Gets a value indicating whether this instance is disposed.</summary>

View File

@@ -1449,6 +1449,9 @@ namespace DynamORM.Helpers.Dynamics
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
if (IsDisposed)
return;
IsDisposed = true; IsDisposed = true;
if (_uncertainResult != null) if (_uncertainResult != null)