Unit's finalization section is not always called
Original Reporter info from Mantis: Marcin Wiazowski
-
Reporter name:
Original Reporter info from Mantis: Marcin Wiazowski
- Reporter name:
Description:
"Finalization" section of the unit is NOT called, when execution of the "Initialization" section is terminated prematurely - like due to calling Halt() or raising an exception. Please see the attached Reproduce demo.
When compiled with Delphi, output is:
Initialization section called in Unit1
Initialization section called in Unit2
Finalization section called in Unit2
Finalization section called in Unit1
When compiled with FPC, output is:
Initialization section called in Unit1
Initialization section called in Unit2
Finalization section called in Unit1
When object's constructor is terminated prematurely, object's destructor is called to finalize the partially created object. Similarly, when unit's initialization section is terminated prematurely, unit's finalization section should be called - just to clean up global objects, already created in the initialization section (like semaphores, mutexes or temporary files).
Current implementation is neither Delphi compatible, nor deinitializes the unit properly.
Adding the "-Mdelphi" compilation command does not change anything. Tested on Win32 platform, with FPC 3.0.4, 3.2.0 (r44257) and 3.3.1 (r44257).
Mantis conversion info:
- Mantis ID: 36754
- Build: 44257
- Version: 3.3.1