Memory Leak in Marshmallow FiredacAdapter

Issue #118 resolved
Todd Flora created an issue

In a previous issue I reported an issue with using Transactions with the Firedac Adapter. Linas quickly applied my suggested fix, which was greatly appreciated. Unfortunately I did not forsee a memory leak that my suggested fix caused.

Since we are now creating a new TFDTransaction each time the user calls BeginTransaction off of the session and this is not an interface type, it needs to be destroyed when the IDBTransaction interface goes out of scope. Also it needs to be freed after the call to the inherited destroy as the parent uses the Transaction Object during the destroy process to rollback the transaction if it is still running when the destroy is invoked.

So Here is my code to fix this issue: Unit - Spring.Persistence.Adapters.Firedac. Add a destructor and free the FTransaction instance after inherited is called.

destructor TFireDACTransactionAdapter.Destroy;
begin
  inherited;
  {
    TFlo - This must be after the call to inherited as the FTransaction is
    used in the inherited destroy to try and rollback the transaction, If this
    is placed before inherited it will throw AV exceptions.
  }
  FreeAndNil(FTransaction);
end;

Comments (5)

  1. Stefan Glienke repo owner
    • changed status to open

    I think only providing an additional ownsobject parameter to the ctor will work properly.

  2. Log in to comment