[fpc-devel] Unwanted finalization

Ludo Brands ludo.brands at free.fr
Sat Oct 13 17:34:59 CEST 2012


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, ExcepInfo,
      ArgErr: pointer): HResult; stdcall;
	...
      begin
	...
          Result := TAutoObjectFactory(Factory).DispTypeInfo.Invoke(Pointer(
            PtrUint(Self) +
TAutoObjectFactory(Factory).DispIntfEntry^.IOffset),
            DispID, Flags, TDispParams(Params), PVariant(VarResult)^,
PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);
	...
	end;

The interface method called (ITypeInfo::Invoke) is defined in activex.pp as 
     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD;
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
pointer.
 
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: WORD;
VAR pDispParams: DISPPARAMS; pVarResult: PVARIANT; pExcepInfo: PEXCEPINFO;
puArgErr: PUINT):HResult;StdCall;
but that requires changing all the code that calls this method. On the other
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. 

Ludo
	




More information about the fpc-devel mailing list