Fix memory leak in get_environmental_variable()

This commit is contained in:
Robert Schumacher 2017-03-31 17:41:24 -07:00 committed by Alexander Karatarakis
parent 4792821a1d
commit 77c90c2df5

View File

@ -167,12 +167,13 @@ namespace vcpkg::System
if (sz == 0)
return nullopt;
auto ret = std::make_unique<std::wstring>(sz, L'\0');
Checks::check_exit(VCPKG_LINE_INFO, MAXDWORD >= ret->size());
auto sz2 = GetEnvironmentVariableW(varname, ret->data(), static_cast<DWORD>(ret->size()));
std::wstring ret(sz, L'\0');
Checks::check_exit(VCPKG_LINE_INFO, MAXDWORD >= ret.size());
auto sz2 = GetEnvironmentVariableW(varname, ret.data(), static_cast<DWORD>(ret.size()));
Checks::check_exit(VCPKG_LINE_INFO, sz2 + 1 == sz);
ret->pop_back();
return *ret.release();
ret.pop_back();
return ret;
}
static bool is_string_keytype(DWORD hkey_type)