Double releasing of TDelphiWebScript instance

Issue #113 resolved
Christian Budde created an issue

In the code below:

var
   Compiler: TDelphiWebScript;
   CompiledProgram: IdwsProgram;
begin
   Compiler := TDelphiWebScript.Create(Self);
   try
      CompiledProgram := Compiler.Compile(' ');
   finally
      Compiler.Free;
   end;
end;

the TDelphiWebScript instance will get released two times. First when Compile.Free is called and a second time when the CompiledProgram interface will get released as it includes a unit list which lists the TDelphiWebScript instance as unit (which has already been released before).

This won't get visible until FastMM4 is added with full debug mode.

Comments (9)

  1. Eric Grange repo owner

    Thanks I can reproduce it and will have a look.

    (I also got your mails, but be aware gmail classified them as spam because of some not respected sender policy)

  2. Eric Grange repo owner

    There is indeed no mechanism yet to notify a program that the compiler was freed, and the program relies on the compiler component for shared elements (like internal units) and for some events (like OnExecutionStarted).

    That said, some IdwsProgram internals have changed with the introduction of the CompilerContext, so it is possible some dependencies may no longer be necessary. And starting new execution could be forbidden when the compiler has been freed.

  3. Eric Grange repo owner

    Hmm, thinking on it, while it would be possible to make IdwsProgram resilient to losing the TDelphiWebScript, if any execution is still running, it would likely fail badly. This is because alongside the TDelphiWebScript, the various units and libraries would likely be released as well (or at least unhooked), and thus the failures would cascade.

    However the TDelphiWebScript should be able to throw up an exception if there are still "child" IdwsProgram out there, this would make the issue easier to spot.

  4. Christian Budde reporter

    Seeing an exception would definitely help to track the issue. At least it would have been easier for me to locate the problem in the first place.

    If properly documented and with the help of the exception there shouldn't be a problem with the restriction to free IdwsProgram instances prior to freeing the compiler.

  5. Christian Budde reporter

    Perfect! Works like a charm. With this I've been able to detect issues in two other places as well.

  6. Eric Grange repo owner

    There is still a not signaled issue when you have units attached to a compiler, that are freed when there are still programs active. They are then properly detached from the compiler, but active programs (and executions) will run into issues.

  7. Log in to comment