Microsoft KB Archive/185231

{|
 * width="100%"|

PRB: Memory Leak When a Fiber Exits the Thread

 * }

Q185231

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * the operating system: Microsoft Windows NT, versions 3.51, 4.0
 * the operating system: Microsoft Windows 2000

-

SYMPTOMS
A small amount of memory is leaked when a fiber causes a thread to exit.

CAUSE
When a thread is converted to a fiber through ConvertThreadToFiber or when a new fiber is created through CreateFiber, an internal fiber data structure is allocated and a pointer to this data structure is returned to the calling program. However, when a fiber causes a thread to exit, either through calling DeleteFiber on itself or simply exiting, the system fails to release the internal fiber data structure allocated for the fiber.

Note that the associated fiber data structure is correctly freed if DeleteFiber is called on another fiber.

RESOLUTION
Call LocalFree passing the LPVOID value returned by CreateFiber or ConvertThreadToFiber to free the fiber data structure just before exiting.

STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION
Usually this is not a problem if you use fibers as intended. Fibers are designed to be employed by a single-threaded application, in which case the leak will never occur. However, if threads with fibers are started and terminated repeatedly, this can cause accumulation of memory leaks and will eventually cause the process to run out of memory.

Additional query words: Fiber, FIBER_DATA, ExitThread, TerminateThread, Memory Leak, Leak

Keywords : kbAPI kbKernBase kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbThread kbDSupport kbGrpDSKernBase

Issue type : kbprb

Technology : kbAudDeveloper kbWin32sSearch kbWin32API