Compiler Use Of Temporary Interface References
Original Reporter info from Mantis: Coxy
-
Reporter name: Simon Cox
Original Reporter info from Mantis: Coxy
- Reporter name: Simon Cox
Description:
Compiler sometimes uses temporary interface references in generated code.
When used and assigned to they cause implementing objects reference count to be incremented. However when the target variable has been assigned to the temporary reference is not immediately set to nil, causing referencing count decrement, but is done in the method exit code.
If the target variable is set nil within the method the implementing objects reference count cannot go to zero and be freed. This can effect outcome of code executed between target variable nil assignment and method exit code.
So compiler use of temporary reference can effect code execution without application developer being aware of it.
Steps to reproduce:
See project file uploaded.
Set breakpoint in TMyObject destructor and at end of Button1 on click handler. When button clicked breakpoints are,
- destructor for item id "IMyInterface"
- Button1 exit code
- destructor for item id "IMyOtherIntf"
Additional information:
See forum discussion https://forum.lazarus.freepascal.org/index.php/topic,53046.0.html
Mantis conversion info:
- Mantis ID: 38415
- Platform: Windows 10
- Version: 3.2.0