Change DiscoveredHdaProperties.controller_name to avoid a memory leak.

This commit is contained in:
jief 2023-11-11 14:36:33 +01:00
parent 87d5576923
commit 22d277d1e4
4 changed files with 7 additions and 6 deletions

View File

@ -110,7 +110,7 @@ public:
template<typename T>
class MutableRef : public T {
public:
T* t;
const T* t;
const T& operator = (const T* other) {
t = other;
return *t;
@ -133,7 +133,7 @@ extern "C" int main(int argc, const char * argv[])
Background = &test;
test = 6;
float test2 = Background.get();
float test2 = Background.get(); (void)test2;
Test t;
TestWithOverride t1;

View File

@ -438,8 +438,9 @@ void ConfigManager::DiscoverDevices()
hda->controller_device_id = Pci.Hdr.DeviceId;
// HDA Controller Info
HdaControllerGetName(((hda->controller_device_id << 16) | hda->controller_vendor_id), &hda->controller_name);
CHAR16* name;
HdaControllerGetName(((hda->controller_device_id << 16) | hda->controller_vendor_id), &name);
hda->controller_name.stealValueFrom(name, wcslen(name) + 1); // we "steal" the value of name, so we sace one memory allocation, and we don't have de free.
if (IsHDMIAudio(HandleArray[Index])) {
DBG(" - HDMI Audio: \n");

View File

@ -90,7 +90,7 @@ class DiscoveredHdaProperties
public:
UINT16 controller_vendor_id = 0;
UINT16 controller_device_id = 0;
CHAR16 *controller_name = 0;
XStringW controller_name = XStringW();
DiscoveredHdaProperties() {}
};

View File

@ -1696,7 +1696,7 @@ REFIT_ABSTRACT_MENU_ENTRY *SubMenuAudio()
for (UINTN i = 0 ; i < gConf.HdaPropertiesArray.size() ; i++) {
SubScreen->AddMenuInfoLine_f("%llu) %ls [%04hX][%04hX]",
(i+1),
gConf.HdaPropertiesArray[i].controller_name,
gConf.HdaPropertiesArray[i].controller_name.wc_str(),
gConf.HdaPropertiesArray[i].controller_vendor_id,
gConf.HdaPropertiesArray[i].controller_device_id
);