各位帮忙看看这段代码存在的内存泄漏,谢谢啦
void CRS2USBDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
HKEY hKey = HKEY_LOCAL_MACHINE;
DWORD numSubKey = 0;
DWORDi;
DWORD sizeSubKey;
TCHARsubKey[255];
TCHAR szValue[MAX_REG_LENGTH];
unsigned char keyValue[255];
DWORD dwType = REG_SZ;
DWORD cbData = MAX_REG_LENGTH;
int iVNSCounter = 0;
memset(keyValue, 0, 255);
switch(nIDEvent)
{
case TIMER_USB_STATUS:
// Operation registry to get info
RegOpenKeyEx(g_HKEY,
L "Drivers\\Active ",
0,
KEY_READ,
&hKey);
RegQueryInfoKey(hKey,
NULL,
NULL,
NULL,
&numSubKey,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
if(numSubKey)
{
for(i=0; i <numSubKey; i++)
{
subKey[0] = '\0 ';
sizeSubKey = 255;
RegEnumKeyEx(hKey,
i,
subKey,
&sizeSubKey,
NULL,
NULL,
NULL,
NULL);
memset(szValue, 0, sizeof(szValue));
wcscpy(szValue, L "Drivers\\Active\\ ");
wcscat(szValue, subKey);
if(RegOpenKeyEx(g_HKEY, szValue, 0, KEY_READ, &hKey)==ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey, TEXT( "Key "), NULL, &dwType, keyValue, &cbData)==ERROR_SUCCESS)
{
SetDlgItemText(IDC_STATIC_TEMP, (LPCTSTR)keyValue);
CString sTmp;
GetDlgItemText(IDC_STATIC_TEMP, sTmp);
CString s1( "Drivers\\USB\\ClientDrivers\\Venus_USB ");
if(sTmp.Compare(s1)==0)
{
iVNSCounter++;
}
}
}
}
}
break;
default:
break;
}
[解决办法]
reg 为什么没有close,
在第二次RegOpenKeyEx 时,没有关闭第一次的handle
[解决办法]
不是都在另一个帖子里说过了么?
怎么一个帖子发2次,是不是分多没处花,给我吧,^_^
这句话不是随便冒出来的,楼主是不是把另一个删了,呵呵!
RegCloseKey在退出时应该调用.