Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Thread support    [ Add a report in this area ]  
Report #:  67691   Status: Closed
BeginThread memory leak
Project:  Delphi Build #:  12.0.3155.16733
Version:    12.0 Submitted By:   Alexey Kazantsev
Report Type:  Minor failure / Design problem Date Reported:  10/8/2008 9:13:54 PM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   266121
Resolution: Fixed (Resolution Comments) Resolved in Build: : 15.0.3573.25335
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
4.00 out of 5
Total Votes: None
If BeginThread cannot create a new thread (any reason) occures memory leak.
Steps to Reproduce:
function BeginThread(SecurityAttributes: Pointer; StackSize: LongWord;
  ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord;
  var ThreadId: LongWord): Integer;
  P: PThreadRec;
  if Assigned(SystemThreadFuncProc) then
    P := PThreadRec(SystemThreadFuncProc(ThreadFunc, Parameter))
    P.Func := ThreadFunc;
    P.Parameter := Parameter;
  IsMultiThread := TRUE;
  Result := CreateThread(SecurityAttributes, StackSize, @ThreadWrapper, P,
    CreationFlags, ThreadID);

Variable P : PThreadRec allocated in BeginThread release in ThreadWrapper which not executed if BeginThread not successful.

Lucian Radulescu at 10/12/2008 7:57:29 PM -
What "any reason"? if Createthread fails, your application is doomed anyway, who cares about a few bytes memory leak :-)

Alexey Kazantsev at 10/13/2008 2:28:25 AM -
No. This may be thread from thread pool. I have situation, when BeginThread fails, but this no kill my application.

Lucian Radulescu at 1/20/2009 1:39:30 PM -
>This may be thread from thread pool

So what ... again, if the system can not create threads your application is doomed anyway :-)

Alexey Kazantsev at 2/1/2009 3:57:02 PM -
Not. Pool can have various count of threads.

Server Response from: ETNACODE01