Dapper.Oracle icon indicating copy to clipboard operation
Dapper.Oracle copied to clipboard

Fix memory leak in TypeHandlerBase.DictionaryKeyComparer.Equals

Open ratacolita opened this issue 4 weeks ago • 0 comments

The bug was in line 22 of TypeHandlerBase.cs: if (x != null && y != null) return false;

This condition returns false when BOTH objects are non-null, which is the normal comparison case. This caused the ConcurrentDictionary to:

  1. Never find existing cache entries (Equals always returns false)
  2. Add a new entry for every SetValue() call
  3. Grow unboundedly causing memory leaks in production

The fix changes the null checks to proper equality semantics: if (x == null && y == null) return true; // Both null = equal if (x == null || y == null) return false; // One null = not equal

Added unit test to verify cache reuse behavior.

🤖 Generated with Claude Code

ratacolita avatar Dec 18 '25 17:12 ratacolita