[fpc-devel] Unwanted finalization

Yury Sidorov jura at cp-lab.com
Sat Oct 13 18:01:20 CEST 2012


Funny, but I have also encountered the problem in this place yesterday 
:) But with PVariant(VarResult)^ in my case.
Yes, the declaration of ITypeInfo.Invoke() should be changed to 
eliminate unwanted compiler magic with managed types when a nil is 
I'll commit the required changes today or tomorrow.

Best Regards!

Yury Sidorov.

----- Original Message ----- 
From: "Ludo Brands" <ludo.brands at free.fr>
To: "'FPC developers' list'" <fpc-devel at lists.freepascal.org>
Sent: Saturday, October 13, 2012 6:34 PM
Subject: [fpc-devel] Unwanted finalization

Dear all,

In comobj.pp I'm getting sometimes a SIGSEGV in the following code:

    function TAutoObject.Invoke(DispID: LongInt; const iid: TGUID;
      LocaleID: longint; Flags: Word; var params; VarResult, 
      ArgErr: pointer): HResult; stdcall;
          Result := 
            PtrUint(Self) +
            DispID, Flags, TDispParams(Params), PVariant(VarResult)^,
PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);

The interface method called (ITypeInfo::Invoke) is defined in 
activex.pp as
     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: 
VAR pDispParams: DISPPARAMS; OUT pVarResult: VARIANT; OUT pExcepInfo:
EXCEPINFO; OUT puArgErr: UINT):HResult;StdCall;

The problem is with the ExcepInfo parameter which is a record.
ITypeInfo::Invoke can have a null pExcepInfo parameter and the
PExcepInfo(ExcepInfo)^ cast causes a call to fpc_finalize with a null

Is there a way to avoid the finalisation of PExcepInfo(ExcepInfo)^ ?
EXCEPINFO has a widestring member...

IMO the ITypeInfo::Invoke method should be changed to
     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: 
VAR pDispParams: DISPPARAMS; pVarResult: PVARIANT; pExcepInfo: 
puArgErr: PUINT):HResult;StdCall;
but that requires changing all the code that calls this method. On the 
hand I'm afraid that any code calling this method with the current
definition will have potentially the same problem with the 
finalization of
the EXCEPINFO record.


fpc-devel maillist  -  fpc-devel at lists.freepascal.org

More information about the fpc-devel mailing list