while (GetLastError() != ERROR_NO_MORE_FILES) {
volumeNameEnd = wcslen(szVolumeName) - 1;
- szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
+ szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
while (!GetVolumePathNamesForVolumeName(szVolumeName, szVolumePathNames, dwVolumePathNamesLen, &dwVolumePathNamesLen)) {
if (GetLastError() != ERROR_MORE_DATA)
break;
- delete[] szVolumePathNames;
- szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
+ delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
+ szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
}
err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
if (err == PDH_MORE_DATA || SUCCEEDED(err))
- pDisplayValuesIn = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeIn];
+ pDisplayValuesIn = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
else
goto die;
err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
if (err == PDH_MORE_DATA || SUCCEEDED(err))
- pDisplayValuesOut = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeOut];
+ pDisplayValuesOut = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
else
goto die;
if (phQuery)
PdhCloseQuery(phQuery);
if (pDisplayValuesIn)
- delete pDisplayValuesIn;
+ delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
if (pDisplayValuesOut)
- delete pDisplayValuesOut;
+ delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
return 3;
}
\ No newline at end of file
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue;
- pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength];
+ pSIDTokenUser = reinterpret_cast<PTOKEN_USER>(new BYTE[dwReturnLength]);
memset(pSIDTokenUser, 0, dwReturnLength);
if (!pSIDTokenUser)
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue;
- AcctName = (LPWSTR) new wchar_t[dwAcctName];
- DomainName = (LPWSTR) new wchar_t[dwDomainName];
+ AcctName = reinterpret_cast<LPWSTR>(new WCHAR[dwAcctName]);
+ DomainName = reinterpret_cast<LPWSTR>(new WCHAR[dwDomainName]);
if (!AcctName || !DomainName)
continue;
if (!wcscmp(AcctName, wuser))
++numProcs;
+ delete[] reinterpret_cast<LPWSTR>(AcctName);
+ delete[] reinterpret_cast<LPWSTR>(DomainName);
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcess);
if (hToken)
CloseHandle(hToken);
+ if (pSIDTokenUser)
+ delete[] reinterpret_cast<PTOKEN_USER>(pSIDTokenUser);
return numProcs;
}
\ No newline at end of file
&& GetLastError() != ERROR_MORE_DATA)
goto die;
- lpServices = new BYTE[*pcbBytesNeeded];
+ lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
cbBufSize = *pcbBytesNeeded;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
die:
if (lpServices)
- delete lpServices;
+ delete[] reinterpret_cast<LPBYTE>(lpServices);
wcout << L"Service " << printInfo.service << L" could not be found" << endl;
return -1;
}