Skip to content

Commit

Permalink
Why did I put the FreePool parameter as const. That's stupid !
Browse files Browse the repository at this point in the history
You must never free a const pointer, by definition.
  • Loading branch information
jief committed Nov 11, 2023
1 parent 22d277d commit 187400d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion MdePkg/Include/Library/MemoryAllocationLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,13 @@ ReallocateReservedPool (
@param Buffer Pointer to the buffer to free.
**/
/*
* Jief : One day, I put JCONST. This is wrong !!! You must never free a ptr that's const.
*/
VOID
EFIAPI
FreePool(
IN JCONST VOID *Buffer
IN VOID *Buffer
);

#endif
7 changes: 4 additions & 3 deletions rEFIt_UEFI/entry_scan/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
// Check for ia.log - InstallESD/createinstallmedia/startosinstall
// Implemented by Sherlocks
if (OSVersion.isEmpty()) {
CONST CHAR8 *s, *fileBuffer;
CONST CHAR8 *s;
UINT8* fileBuffer;
// CHAR8 *Res5 = (__typeof__(Res5))AllocateZeroPool(5);
// CHAR8 *Res6 = (__typeof__(Res6))AllocateZeroPool(6);
// CHAR8 *Res7 = (__typeof__(Res7))AllocateZeroPool(7);
Expand All @@ -696,10 +697,10 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
if (FileExists (Volume->RootDir, InstallerLog)) {
Status = egLoadFile(Volume->RootDir, InstallerLog.wc_str(), (UINT8 **)&fileBuffer, &fileLen);
Status = egLoadFile(Volume->RootDir, InstallerLog.wc_str(), &fileBuffer, &fileLen);
if (!EFI_ERROR(Status)) {
XString8 targetString;
targetString.strncpy(fileBuffer, fileLen);
targetString.strncpy((CHAR8*)fileBuffer, fileLen);
// s = SearchString(targetString, fileLen, "Running OS Build: Mac OS X ", 27);
s = AsciiStrStr(targetString.c_str(), "Running OS Build: Mac OS X ");
if (s[31] == ' ') {
Expand Down
7 changes: 4 additions & 3 deletions rEFIt_UEFI/libeg/XTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ EFI_STATUS Status = EFI_NOT_FOUND;
}
TestTheme.setEmpty();
}
FreePool(ChosenTheme);
ChosenTheme = NULL;
//FreePool(ChosenTheme); // ChosenTheme is an argument passed here, so the callee is "own" that memory.
//ChosenTheme = NULL; // Why is this bad pratice : it's assuming that ChosenTheme was dynamically allocated and freeable. What is this the content of an XString ?
}
// Try to get theme from settings
if (ThemeDict == NULL) {
Expand Down Expand Up @@ -204,7 +204,8 @@ EFI_STATUS Status = EFI_NOT_FOUND;
}
}
if (ChosenTheme != NULL) {
FreePool(ChosenTheme);
//FreePool(ChosenTheme); // ChosenTheme is an argument passed here, so the callee is "own" that memory.
// Why is this bad pratice : it's assuming that ChosenTheme was dynamically allocated and freeable. What is this the content of an XString ?
}
if (!ThemeX->TypeSVG) {
ThemeX->PrepareFont();
Expand Down
4 changes: 3 additions & 1 deletion rEFIt_UEFI/refit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,9 @@ RefitMain (IN EFI_HANDLE ImageHandle,
if (!GlobalConfig.isFastBoot()) {
if (gThemeNeedInit) {
UINTN Size = 0;
InitTheme((CHAR8*)GetNvramVariable(L"Clover.Theme", gEfiAppleBootGuid, NULL, &Size));
CHAR8* ChoosenTheme = (CHAR8*)GetNvramVariable(L"Clover.Theme", gEfiAppleBootGuid, NULL, &Size);
InitTheme(ChoosenTheme);
FreePool(ChoosenTheme);
gThemeNeedInit = false;
} else if (GlobalConfig.gThemeChanged) {
DBG("change theme\n");
Expand Down

0 comments on commit 187400d

Please sign in to comment.