[WinAPI] WTSQuerySessionInformation memory leak

http://ezbeat.tistory.com/217
http://blog.naver.com/PostView.nhn?blogId=hypermin&logNo=70069030137&parentCategoryNo=45&viewDate=&currentPage=1&listtype=0&userTopListOpen=true&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=1
http://www.jj54.com/72898-BUG-58-The-WTSQuerySessionInformation-40-41-Function-Returns-Invalid-Client-Address/
Hello,
I've just came across that the WTSQuerySessionInformation function on
Windows 2000 Professional SP4 (all fixes are installed) has a bug.
WTSQuerySessionInformation doesn't free memory and if I call it in the loop
the memory leakage can be huge!
This is an example:
/*
* This program demonstrates memory leak in WTSQuerySessionInformation()
* function.
*
* Application just calls WTSQuerySessionInformation() continiously in a
loop
* and frees any buffer which is returned. On W2K SP4 Workstation
* WTSQuerySessionInformation() always returns error ERROR_APP_WRONG_OS,
* sets pUserName to NULL (nothing to free). However, it can be seen by
* observing the application memory usage that virtual memory size
constantly
* grows by 4Kb. It seems to be some memory leak inside
* WTSQuerySessionInformation().
*
*
* OS: Windows 2000 Workstaion SP4 with all updates (up to 31 May 2005)
*
* Author: Sten (sten@smartline.ru), 2005
*/
#include <stdio.h>
#include <windows.h>
#include <wtsapi32.h>
void main (void)
{
LPTSTR pUserName;
DWORD dwBytesReturned;
while (1)
{
pUserName = NULL;
dwBytesReturned = 0;

if (!WTSQuerySessionInformation(
WTS_CURRENT_SERVER_HANDLE,
0,
WTSUserName,
&pUserName,
&dwBytesReturned))
{
printf("WTSQuerySessionInformation() failed [%08X]!\n",
GetLastError());
}
if (pUserName)
WTSFreeMemory(pUserName);
Sleep(100);
}
}

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/a197c527-da91-4ef0-8230-330f58f9abb4/

댓글

이 블로그의 인기 게시물

[WinAPI] 모달리스 다이얼로그 설명

[WinDbg] Debugging a stack overflow

[WinDbg] first-chance, second-chance Exception