Skip to content

Commit ab15a4a

Browse files
jojastahlcincuranet
authored andcommitted
Fix possible leak because WeakReferences are not reused but a new one is inserted on each AddPreparedCommand
1 parent ae59e46 commit ab15a4a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,12 @@ public DataTable GetSchema(string collectionName, string[] restrictions)
342342

343343
public void AddPreparedCommand(FbCommand command)
344344
{
345-
int position = _preparedCommands.Count;
345+
int position = -1;
346346
for (int i = 0; i < _preparedCommands.Count; i++)
347347
{
348348
if (!_preparedCommands[i].TryGetTarget(out FbCommand current))
349349
{
350350
position = i;
351-
break;
352351
}
353352
else
354353
{
@@ -358,7 +357,10 @@ public void AddPreparedCommand(FbCommand command)
358357
}
359358
}
360359
}
361-
_preparedCommands.Insert(position, new WeakReference(command));
360+
if (position >= 0)
361+
_preparedCommands[position].Target = command;
362+
else
363+
_preparedCommands.Add(new WeakReference(command));
362364
}
363365

364366
public void RemovePreparedCommand(FbCommand command)

0 commit comments

Comments
 (0)