fix: fix memory leak on Windows

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-07-16 20:08:02 +02:00
parent a4672ba00f
commit 17ea51ce27
No known key found for this signature in database
GPG Key ID: C10411294912A422

View File

@ -202,8 +202,6 @@ QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
{
// Read the current type version from the registry.
// This will be used to find any key that contains the JavaHome value.
TCHAR *value = new TCHAR[0];
DWORD valueSz = 0;
TCHAR subKeyName[255];
DWORD subKeyNameSize, numSubKeys, retCode;
@ -231,9 +229,8 @@ QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
{
// Read the JavaHome value to find where Java is installed.
delete [] value;
value = new TCHAR[0];
valueSz = 0;
TCHAR *value = NULL;
DWORD valueSz = 0;
if (RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, (BYTE *)value,
&valueSz) == ERROR_MORE_DATA)
{
@ -242,6 +239,7 @@ QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
&valueSz);
QString newValue = QString::fromWCharArray(value);
delete [] value;
// Now, we construct the version object and add it to the list.
JavaInstallPtr javaVersion(new JavaInstall());