mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-11 15:56:17 -07:00
Don't use explicit memory management
And avoid dangling pointers.
This commit is contained in:
parent
8a708fd97e
commit
bbd936fdfa
9 changed files with 28 additions and 36 deletions
|
@ -128,26 +128,17 @@ namespace
|
|||
|
||||
QString getRegValue(const HKEY handle, const QString &name = {})
|
||||
{
|
||||
QString result;
|
||||
|
||||
const std::wstring nameWStr = name.toStdWString();
|
||||
DWORD type = 0;
|
||||
DWORD cbData = 0;
|
||||
LPWSTR lpValueName = NULL;
|
||||
if (!name.isEmpty())
|
||||
{
|
||||
lpValueName = new WCHAR[name.size() + 1];
|
||||
name.toWCharArray(lpValueName);
|
||||
lpValueName[name.size()] = 0;
|
||||
}
|
||||
|
||||
// Discover the size of the value
|
||||
::RegQueryValueExW(handle, lpValueName, NULL, &type, NULL, &cbData);
|
||||
::RegQueryValueExW(handle, nameWStr.c_str(), NULL, &type, NULL, &cbData);
|
||||
DWORD cBuffer = (cbData / sizeof(WCHAR)) + 1;
|
||||
LPWSTR lpData = new WCHAR[cBuffer];
|
||||
LONG res = ::RegQueryValueExW(handle, lpValueName, NULL, &type, (LPBYTE)lpData, &cbData);
|
||||
if (lpValueName)
|
||||
delete[] lpValueName;
|
||||
LONG res = ::RegQueryValueExW(handle, nameWStr.c_str(), NULL, &type, (LPBYTE)lpData, &cbData);
|
||||
|
||||
QString result;
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
lpData[cBuffer - 1] = 0;
|
||||
|
@ -186,18 +177,14 @@ namespace
|
|||
bool found = false;
|
||||
while (!found && !versions.empty())
|
||||
{
|
||||
const QString version = versions.takeLast() + u"\\InstallPath";
|
||||
LPWSTR lpSubkey = new WCHAR[version.size() + 1];
|
||||
version.toWCharArray(lpSubkey);
|
||||
lpSubkey[version.size()] = 0;
|
||||
const std::wstring version = QString(versions.takeLast() + u"\\InstallPath").toStdWString();
|
||||
|
||||
HKEY hkInstallPath;
|
||||
res = ::RegOpenKeyExW(hkPythonCore, lpSubkey, 0, samDesired, &hkInstallPath);
|
||||
delete[] lpSubkey;
|
||||
res = ::RegOpenKeyExW(hkPythonCore, version.c_str(), 0, samDesired, &hkInstallPath);
|
||||
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
qDebug("Detected possible Python v%s location", qUtf8Printable(version));
|
||||
qDebug("Detected possible Python v%ls location", version.c_str());
|
||||
path = getRegValue(hkInstallPath);
|
||||
::RegCloseKey(hkInstallPath);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue