PRB: Memory Leak When a Fiber Exits the Thread (185231)



The information in this article applies to:

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

This article was previously published under Q185231

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.

Modification Type:MajorLast Reviewed:3/16/2004
Keywords:kbAPI kbKernBase kbprb kbThread KB185231