Ticket #84 (closed defect: fixed)

Opened 3 months ago

Last modified 7 weeks ago

fix memory leak in wwme

Reported by: gordon_gidluck Owned by: gordon_gidluck
Priority: major Milestone: V19-RC1
Component: host-api-wmme Version: 1.0
Keywords: Cc:

Description

submitted by bodo.maass@… on 08/22/2008

SUMMARY

All C Run-time functions except the signal() function work correctly when used in threads that are created by the CreateThread?() function. However, depending on what CRT functions are called, there may be a small memory leak when threads are terminated. Calling strlen(), for example, does not trigger the allocation of the CRT thread data-block, and calling malloc(), fopen(), _open(), strtok(), ctime(), or localtime() causes allocation of a CRT per-thread data-block, which may cause a memory leak.

details are here: http://support.microsoft.com/default.aspx/kb/104641

This defect also applies to wdmks and wasapi portAudio api's.

The solution is to use _beginthreadex() instead of CreateThread?() and also _endthreadex() instead of ExitThread?() .

Attachments

[Portaudio] CreateThread vs. _beginthreadex in WMME.eml (4.4 KB) - added by gordon_gidluck 3 months ago.
original email from Bodo
[Portaudio] CreateThread vs. _beginthreadex in WMME[2].eml (6.6 KB) - added by gordon_gidluck 3 months ago.
followup emails
[Portaudio] CreateThread vs. _beginthreadex in WMME.2.eml (5.4 KB) - added by gordon_gidluck 7 weeks ago.

Change History

Changed 3 months ago by gordon_gidluck

original email from Bodo

Changed 3 months ago by gordon_gidluck

followup emails

Changed 3 months ago by gordon_gidluck

  • owner changed from rossb to gordon_gidluck

Changed 2 months ago by gordon_gidluck

Changed CreateThread? to _beginthreadex in pa_win_wdmks.c and pa_win_wmme.c . Changed ExitThread? to _endthreadex. Ran into an issue with pa_win_wasapi.cpp . Will turn that over to David Viens to review before recommitting a change.

Changed 7 weeks ago by gordon_gidluck

cygwin compile reported broken by sb-lst@…

Changed 7 weeks ago by gordon_gidluck

Changed 7 weeks ago by gordon_gidluck

Changed the call to _beginthreadex or CreateThread? based upon whether or not CYGWIN is defined.

/* use CreateThread for CYGWIN, _beginthreadex for all others */
#ifndef __CYGWIN__
#define CREATE_THREAD (HANDLE)_beginthreadex( 0, 0, ProcessingThreadProc, stream, 0, &stream->processingThreadId )
#else
#define CREATE_THREAD CreateThread( 0, 0, ProcessingThreadProc, stream, 0, &stream->processingThreadId )
#endif

Since wasapi is C++, I employed typecasting to handle the more strict type-checking of parameters. I found a good tutorial related to this subject here:
http://www.mtholyoke.edu/courses/dstrahma/cs322/lab3andproj.htm

#ifndef __CYGWIN__
#define CREATE_THREAD (HANDLE) _beginthreadex(NULL, 0, (unsigned (_stdcall *)(void *))ProcThread, (LPVOID) stream, 0, (unsigned *)&stream->dwThreadId)
#else
#define CREATE_THREAD CreateThread(NULL, 0, ProcThread, (LPVOID) stream, 0, &stream->dwThreadId)
#endif

wdmks referenced _endthreadex so this was handled using the same conditional statement.

#ifndef __CYGWIN__
#define EXIT_THREAD _endthreadex(0)
#else
#define EXIT_THREAD ExitThread(0)
#endif

Changed 7 weeks ago by gordon_gidluck

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.