|
void FillListBox (HWND hwndList)
{
int iLength ;
TCHAR *pVarBlock, *pVarBeg, *pVarEnd, *pVarName ;
pVarBlock = GetEnvironmentStrings () ;// Get pointer to environment block
while (*pVarBlock)
{
if (*pVarBlock != '=') // Skip variable names beginning with '='
{
pVarBeg = pVarBlock ; // Beginning of variable name
while (*pVarBlock++ != '=') ; // Scan until '='
pVarEnd = pVarBlock - 1 ; // Points to '=' sign
iLength = pVarEnd - pVarBeg ; // Length of variable name
// Allocate memory for the variable name and terminating
// zero. Copy the variable name and append a zero.
pVarName = (TCHAR *)calloc (iLength + 1, sizeof (TCHAR)) ;
CopyMemory (pVarName, pVarBeg, iLength * sizeof (TCHAR)) ;//Copies a block of memory
pVarName[iLength] = '\0' ;
// Put the variable name in the list box and free memory.
SendMessage (hwndList, LB_ADDSTRING, 0, (LPARAM) pVarName) ;
free (pVarName) ;
}
while (*pVarBlock++ != '\0') ; // Scan until terminating zero
}
FreeEnvironmentStrings (pVarBlock) ;
}
调试信息
......
“ENVIRON.exe”: 已卸载“C:\WINDOWS\system32\version.dll”
“ENVIRON.exe”: 已加载“C:\WINDOWS\system32\MSCTFIME.IME”,未加载任何符号。
HEAP[ENVIRON.exe]: Invalid Address specified to RtlFreeHeap( 00140000, 001759EF )
ENVIRON.exe 中的 0x7c921230 处未处理的异常: 用户断点 。
程序“[3480] ENVIRON.exe: 本机”已退出,返回值为 0 (0x0)。
程序“[3480] ENVIRON.exe”已退出,返回值为 0 (0x0)。
在程序代码中注释该函数后,内存泄露的提示消失
谢谢先 |
|