From 64de6d0fef712592a8baf7caf9670488b8f58b3c Mon Sep 17 00:00:00 2001 From: asava Date: Fri, 1 May 2020 03:14:11 +0300 Subject: [PATCH] Correct some problems when changing config files --- rEFIt_UEFI/Platform/Settings.cpp | 29 ++++++++++++++++++++++------- rEFIt_UEFI/refit/main.cpp | 12 ++++++++---- rEFIt_UEFI/refit/menu.cpp | 6 +++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index c38962c22..4dbe0d57f 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -65,7 +65,7 @@ INTN LayoutBannerOffset = 64; INTN LayoutTextOffset = 0; INTN LayoutButtonOffset = 0; -ACPI_PATCHED_AML *ACPIPatchedAML; +ACPI_PATCHED_AML *ACPIPatchedAML = NULL; SIDELOAD_KEXT *InjectKextList = NULL; //SYSVARIABLES *SysVariables; CHAR16 *IconFormat = NULL; @@ -96,7 +96,7 @@ UINTN ThemesNum = 0; CONST CHAR16 *ThemesList[100]; //no more then 100 themes? UINTN ConfigsNum; CHAR16 *ConfigsList[20]; -UINTN DsdtsNum; +UINTN DsdtsNum = 0; CHAR16 *DsdtsList[20]; UINTN AudioNum; HDA_OUTPUTS AudioList[20]; @@ -3262,6 +3262,13 @@ GetListOfDsdts () INTN NameLen; CHAR16* AcpiPath = PoolPrint(L"%s\\ACPI\\patched", OEMPath); + if (DsdtsNum > 0) { + for (UINTN i = 0; i < DsdtsNum; i++) { + if (DsdtsList[DsdtsNum] != NULL) { + FreePool(DsdtsList[DsdtsNum]); + } + } + } DsdtsNum = 0; OldChosenDsdt = 0xFFFF; @@ -3273,13 +3280,13 @@ GetListOfDsdts () continue; } - snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); + snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); if (FileExists(SelfRootDir, FullName)) { if (StriCmp(DirEntry->FileName, gSettings.DsdtName) == 0) { OldChosenDsdt = DsdtsNum; } NameLen = StrLen(DirEntry->FileName); //with ".aml" - DsdtsList[DsdtsNum] = (CHAR16*)AllocateCopyPool(NameLen * sizeof(CHAR16) + 2, DirEntry->FileName); + DsdtsList[DsdtsNum] = (CHAR16*)AllocateCopyPool(NameLen * sizeof(CHAR16) + 2, DirEntry->FileName); // if changing, notice freepool above DsdtsList[DsdtsNum++][NameLen] = L'\0'; DBG("- %ls\n", DirEntry->FileName); } @@ -3297,6 +3304,14 @@ GetListOfACPI () INTN i, Count = gSettings.DisabledAMLCount; CHAR16* AcpiPath = PoolPrint(L"%s\\ACPI\\patched", OEMPath); + while (ACPIPatchedAML != NULL) { + if (ACPIPatchedAML->FileName) { + FreePool(ACPIPatchedAML->FileName); + } + ACPIPatchedAMLTmp = ACPIPatchedAML; + ACPIPatchedAML = ACPIPatchedAML->Next; + FreePool(ACPIPatchedAMLTmp); + } ACPIPatchedAML = NULL; DirIterOpen(SelfRootDir, AcpiPath, &DirIter); @@ -3310,11 +3325,11 @@ GetListOfACPI () continue; } - snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); + snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); if (FileExists(SelfRootDir, FullName)) { BOOLEAN ACPIDisabled = FALSE; - ACPIPatchedAMLTmp = (__typeof__(ACPIPatchedAMLTmp))AllocateZeroPool(sizeof(ACPI_PATCHED_AML)); - ACPIPatchedAMLTmp->FileName = PoolPrint(L"%s", DirEntry->FileName); + ACPIPatchedAMLTmp = (__typeof__(ACPIPatchedAMLTmp))AllocateZeroPool(sizeof(ACPI_PATCHED_AML)); // if changing, notice freepool above + ACPIPatchedAMLTmp->FileName = PoolPrint(L"%s", DirEntry->FileName); // if changing, notice freepool above for (i = 0; i < Count; i++) { if ((gSettings.DisabledAML[i] != NULL) && diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 0b0ed02af..09833ffda 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -2364,12 +2364,17 @@ RefitMain (IN EFI_HANDLE ImageHandle, } - GetListOfDsdts(); //only after GetUserSettings - GetListOfACPI(); //ssdt and other tables - AfterTool = FALSE; gGuiIsReady = TRUE; + gBootChanged = TRUE; + gThemeChanged = TRUE; do { + if (gBootChanged && gThemeChanged) { // config changed + GetListOfDsdts(); //only after GetUserSettings + GetListOfACPI(); //ssdt and other tables + } + gBootChanged = FALSE; + MainMenu.Entries.Empty(); OptionMenu.Entries.Empty(); InitKextList(); @@ -2415,7 +2420,6 @@ RefitMain (IN EFI_HANDLE ImageHandle, if (gThemeNeedInit) { InitTheme(TRUE, &Now); gThemeNeedInit = FALSE; - gThemeChanged = TRUE; } else if (gThemeChanged) { DBG("change theme\n"); InitTheme(FALSE, NULL); diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index 3f16fa54f..2e719926b 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -1020,12 +1020,12 @@ VOID ApplyInputs(VOID) if (InputItems[i].Valid) { Status = LoadUserSettings(SelfRootDir, ConfigsList[OldChosenConfig], &dict); if (!EFI_ERROR(Status)) { + gBootChanged = TRUE; + gThemeChanged = TRUE; Status = GetUserSettings(SelfRootDir, dict); if (gConfigDict[2]) FreeTag(gConfigDict[2]); gConfigDict[2] = dict; - snwprintf(gSettings.ConfigName, 64, "%ls", ConfigsList[OldChosenConfig]); - gBootChanged = TRUE; - gThemeChanged = TRUE; + snwprintf(gSettings.ConfigName, 64, "%ls", ConfigsList[OldChosenConfig]); } FillInputs(FALSE); NeedSave = FALSE;