View Issue Details

IDProjectCategoryView StatusLast Update
0020808FPCRTLpublic2014-03-06 10:22
ReporterCraig PetersonAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.7.1Product Build 
Target VersionFixed in Version3.0.0 
Summary0020808: ReferenceInterface(opInsert) is broken
DescriptionReferenceInterface is supposed to add and remove the interface's implementing component from the FFreeNotifies list, but instead, when called with opInsert, it just immediately calls Notification. Since it isn't actually added to the FreeNotifies list, the calling component never receives notification when the implementing component is freed.

The program listed in "Steps to Reproduce" prints "Pass" under Delphi and "Fail" under FreePascal. The correct implementation is given in Additional Information.
Steps To Reproduceprogram project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}

var
  Notified: Boolean;

type
  TMyComponent = class(TComponent)
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
  end;

procedure TMyComponent.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  Notified := True;
end;

var
  Comp1, Comp2: TComponent;
  Intf: IUnknown;
begin
  Comp1 := TMyComponent.Create(nil);
  Comp2 := TMyComponent.Create(nil);
  Intf := Comp2;
  Comp1.ReferenceInterface(Intf, opInsert);
  Notified := False;
  Comp2.Free;
  if Notified then
    WriteLn('Pass')
  else
    WriteLn('Fail')
end.
Additional Informationprocedure TComponent.ReferenceInterface(const intf:IInterface;op:TOperation);
var ref : IInterfaceComponentReference;
    comp : TComponent;
begin
 if assigned(intf) and supports(intf,IInterfaceComponentReference,ref) then
   begin
    comp:=ref.getcomponent;
    if op = opInsert then
      comp.FreeNotification(Self)
    else
      comp.RemoveFreeNotification(Self);
   end;
end;
TagsNo tags attached.
Fixed in Revision20616
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0021458 resolvedMichael Van Canneyt FreeNotification and opRemove leads to crash 

Activities

Craig Peterson

2011-12-04 05:32

reporter   ~0054686

Steps to Reproduce didn't make it through. Repost:


program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}

var
  Notified: Boolean;

type
  TMyComponent = class(TComponent)
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
  end;

procedure TMyComponent.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  Notified := True;
end;

var
  Comp1, Comp2: TComponent;
  Intf: IUnknown;
begin
  Comp1 := TMyComponent.Create(nil);
  Comp2 := TMyComponent.Create(nil);
  Intf := Comp2;
  Comp1.ReferenceInterface(Intf, opInsert);
  Notified := False;
  Comp2.Free;
  if Notified then
    WriteLn('Pass')
  else
    WriteLn('Fail')
end.

Marco van de Voort

2012-03-24 18:28

manager   ~0057987

Committed, thanks

Issue History

Date Modified Username Field Change
2011-12-04 05:30 Craig Peterson New Issue
2011-12-04 05:32 Craig Peterson Note Added: 0054686
2011-12-04 15:56 Jonas Maebe Status new => assigned
2011-12-04 15:56 Jonas Maebe Assigned To => Michael Van Canneyt
2012-03-24 18:22 Marco van de Voort Relationship added related to 0021458
2012-03-24 18:28 Marco van de Voort Fixed in Revision => 20616
2012-03-24 18:28 Marco van de Voort Status assigned => resolved
2012-03-24 18:28 Marco van de Voort Fixed in Version => 2.7.1
2012-03-24 18:28 Marco van de Voort Resolution open => fixed
2012-03-24 18:28 Marco van de Voort Note Added: 0057987
2014-03-06 10:22 Michael Van Canneyt Status resolved => closed