Skip to content

UniDAC CreateAnotherDatabaseConnection creates a TUniConnection that is never freed #91

Description

@bero

TBoldUniDACConnection.CreateAnotherDatabaseConnection (Source/Persistence/UniDAC/BoldUniDACInterfaces.pas) creates a TUniConnection with no owner, assigns the current connection's settings to it and wraps it in a new TBoldUniDACConnection - but nothing ever frees that TUniConnection. The code itself carries the question: TUniConnection.Create(nil); // owner ?. Found while fixing #90.

Symptom

Every extra connection handed out by CreateAnotherDatabaseConnection leaks its TUniConnection (and the provider objects behind it) when the wrapper is freed. Users of the path: TBoldDbCopy (one per source and destination), the threaded DB validator (one per worker), and any application code that wants a second connection on the same settings.

Root cause

The FireDAC adapter solves the same lifetime with an ownership flag: TBoldFireDACConnection.CreateAnotherDatabaseConnection sets fOwnsConnection := True on the new wrapper and Destroy frees the TFDConnection when the flag is set. The UniDAC adapter has no such flag; its destructor only releases the cached objects (#90) and leaves fUniConnection alone - correct for the normal case, where the component belongs to the TBoldDatabaseAdapterUniDAC, wrong for the connection the wrapper created itself.

Separate from this issue: the callers themselves (TBoldDbCopy, TBoldDbValidator worker) drop the returned interface without freeing the wrapper object, which is not reference counted - so the wrapper leaks on both adapters regardless. That is a caller-side defect and is not changed here.

Fix

  • TBoldUniDACConnection: add fOwnsConnection; CreateAnotherDatabaseConnection sets it on the wrapper it returns; Destroy frees fUniConnection when it is set. Same shape as the FireDAC adapter.

Files changed

Testing

  • RED: TestCreateAnotherDatabaseConnectionOwnsItsConnection - create and free an extra connection through IBoldDatabase; after a warm-up pass the allocated-block count must not grow — failed with allocated blocks grew by 380 (TUniConnection x 2 and its transaction/option objects in the FastMM report)
  • GREEN after the fix; Test.PersistenceUniDAC 7/7 on SQL Server, no FastMM shutdown report
  • Default Debug build unaffected (UniDAC sources are not on its path)
  • Port to the Attracs fork of Bold

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions