View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006355FPCRTLpublic2005-10-16 12:002012-06-06 21:04
ReporterFPC core team 
Assigned To 
PlatformOSWin32OS Version
Product VersionProduct Build 
Target VersionFixed in Version 
Summary0006355: Thread create in dll causes delayed access violation.
DescriptionI use: FPC version 2.0.0 [2005/05/08] and Delphi 6 with RTL Update 3 and General Update 2

When a thread is created in a dll, in suspended mode or otherwise, a delayed access violation occurs that only shows up upon program termination. (Access violation at address 1000AAC0. Read of address 1000AAC0.) The address does of course vary from program to program.

This error has one more prerequisite: the calling program (exe) must have a delphi VCL TForm or descendant VISIBLE (note: inivisible forms dont cause the error). And this form must be visible during the FREELIBRARY call, if the form is FREED before the call no errors are caused.

Also note: when the same DLL is compiled with Delphi everything works fine.

I do not think this is a bug in Delphi as the TForm is too widely used and the bug would be present in almost every Delphi program.

This is getting more confusing but, importantly: if FreeLibrary is called AFTER the form has been freed then there is no error, THEREFORE, the bug must be in the DLL's RTL (i think) finalization code.

I could just wait until right at the end of my program to call all "FreeLibrary"s but that just wouldnt be cool ;)

There are two source files included.
Additional InformationReporter: Misha Strong
EMail: skiy at actionpos dot co dot za
Tagsdynamic library
Fixed in Revision
Attached Files? file icon code.pp [^] (1,933 bytes) 2005-10-16 12:00

- Relationships
related to 0022115assignedSven Barth BeginThread started in dll started from thread = random crashes 
related to 0006401closedMarco van de Voort More info on bug report 4444 

-  Notes
Marco van de Voort (manager)
2008-12-28 11:06

Problem is still there (D7, 2.3.1), but the problem seems to be Delphi internal.

Some observations:
- The crash in in the end. IOW in the finalization. Not in the indicated spot.
- Pauzing (breakpoint) before the freelibrary doesn't matter. If you break/continue on either the free or freelibrary, the exception doesn't happen ->
Seems to be a race condition.
- To be exact in a windows message dispatch of the "hide" statement of the form's free method. Further debugging is hard, since breaking influences the program.

I suspect it is something relating to Delphi trying to send a message to either a thread or the DLL handle, which is already destroyed, while with delphi-delphi behaviour this is deregistered properly or so.

In short: I doubt this is a real FPC bug. It might be simply that there is some additional magic involved that doesn't work right if both sides are not delphi.

- Issue History
Date Modified Username Field Change
2007-01-05 11:46 Jonas Maebe Relationship added related to 0006401
2008-12-28 11:06 Marco van de Voort Note Added: 0024014
2008-12-28 11:06 Marco van de Voort Tag Attached: dynamic library
2012-06-06 21:04 Jonas Maebe Relationship added related to 0022115

MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker