renan-guimaraes / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Possible double-free issue with external units #388

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a TDelphiWebScript
2. Create an external unit, and assign its Script property to the scripter 
object from step 1.
3. Call Free on the scripter object without freeing the external unit first.

What is the expected output? What do you see instead?

Expected: Everything should clean up properly.
Observed: Memory error when the compiler cleans up its Units list in the 
destructor.

Here's what's going on:

Scripter component gets destroyed.
TComponent.Destroy calls RemoveFreeNotifications.
RemoveFreeNotifications calls Notification(self, opRemove) on the unit object.
This invokes:

procedure TdwsAbstractUnit.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FScript) then
    FScript := nil;
end;

FScript is set to nil, but because the field is changed directly, the following 
line in TdwsAbstractUnit.SetScript was not called:

      FScript.RemoveUnit(Self);

This leaves an interface reference to the unit object sitting around in the 
compiler's unit list, while the object is destroyed out from under it.

To fix this, TdwsAbstractUnit.Notification should instead say "self.Script := 
nil;".

Original issue reported on code.google.com by masonwhe...@gmail.com on 8 May 2013 at 11:11

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r2057.

Original comment by zar...@gmail.com on 10 May 2013 at 6:36