Fix GetOwnVersion() freeing filename too soon

This commit is contained in:
Adam Demasi 2024-09-30 03:05:40 +09:30
parent c99bd36cd1
commit 0848263d4f
No known key found for this signature in database
GPG key ID: 5D3B26B3D58C7D91

View file

@ -6,6 +6,8 @@ static LPWSTR _version;
HRESULT GetOwnVersion(LPWSTR *version) {
if (!_loadedOwnVersion) {
_loadedOwnVersion = TRUE;
LPWSTR filename;
GetOwnFileName(&filename);
@ -16,14 +18,15 @@ HRESULT GetOwnVersion(LPWSTR *version) {
return HRESULT_FROM_WIN32(GetLastError());
}
LocalFree(filename);
LPVOID verInfo = LocalAlloc(LPTR, verInfoSize);
if (!GetFileVersionInfo(filename, verHandle, verInfoSize, verInfo)) {
LocalFree(filename);
LocalFree(verInfo);
return HRESULT_FROM_WIN32(GetLastError());
}
LocalFree(filename);
UINT size;
if (!VerQueryValue(verInfo, L"\\StringFileInfo\\040904B0\\ProductVersion", (LPVOID *)&_version, &size)) {
LocalFree(verInfo);