Hi, Ray You'd better to set the FileBuffer pointer to NULL after free it, otherwise the function will return a freed pointer if the second LoadFile() is falied. Other part is good to me. + if (FileBuffer != NULL) { + FreePool (FileBuffer); + }
Reviewed-by: Fu Siyuan <siyuan...@intel.com> > -----Original Message----- > From: Ni, Ruiyu > Sent: Wednesday, February 24, 2016 3:40 PM > To: edk2-devel@lists.01.org > Cc: Ni, Ruiyu <ruiyu...@intel.com>; Fu, Siyuan <siyuan...@intel.com> > Subject: [Patch 3/4] MdeModulePkg/Bds: Support short-form URI boot. > > The patch adds short-form URI boot support to follow > UEFI Spec. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni <ruiyu...@intel.com> > Cc: Siyuan Fu <siyuan...@intel.com> > --- > MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 72 > ++++++++++++++++++++++++ > 1 file changed, 72 insertions(+) > > diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > index 35234ba..9ce841e 100644 > --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > @@ -1182,6 +1182,72 @@ BmExpandFileDevicePath ( > } > > /** > + Expand URI device path node to be full device path in platform. > + > + @param FilePath The device path pointing to a load option. > + It could be a short-form device path. > + @param FullPath Return the full device path of the load option after > + short-form device path expanding. > + Caller is responsible to free it. > + @param FileSize Return the load option size. > + > + @return The load option buffer. Caller is responsible to free the memory. > +**/ > +VOID * > +BmExpandUriDevicePath ( > + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, > + OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, > + OUT UINTN *FileSize > + ) > +{ > + EFI_STATUS Status; > + UINTN Index; > + UINTN HandleCount; > + EFI_HANDLE *Handles; > + EFI_LOAD_FILE_PROTOCOL *LoadFile; > + VOID *FileBuffer; > + > + EfiBootManagerConnectAll (); > + Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, > NULL, &HandleCount, &Handles); > + if (EFI_ERROR (Status)) { > + HandleCount = 0; > + Handles = NULL; > + } > + > + FileBuffer = NULL; > + > + for (Index = 0; Index < HandleCount; Index++) { > + Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadFileProtocolGuid, > (VOID *) &LoadFile); > + ASSERT_EFI_ERROR (Status); > + > + FileBuffer = NULL; > + Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, > FileBuffer); > + if (Status == EFI_BUFFER_TOO_SMALL) { > + FileBuffer = AllocatePool (*FileSize); > + if (FileBuffer == NULL) { > + break; > + } > + Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, > FileBuffer); > + } > + > + if (!EFI_ERROR (Status)) { > + *FullPath = DuplicateDevicePath (DevicePathFromHandle > (Handles[Index])); > + break; > + } > + > + if (FileBuffer != NULL) { > + FreePool (FileBuffer); > + } > + } > + > + if (Handles != NULL) { > + FreePool (Handles); > + } > + > + return FileBuffer; > +} > + > +/** > Save the partition DevicePath to the CachedDevicePath as the first > instance. > > @param CachedDevicePath The device path cache. > @@ -1718,6 +1784,12 @@ BmGetLoadOptionBuffer ( > // Expand the File-path device path > // > return BmExpandFileDevicePath (FilePath, FullPath, FileSize); > + } else if ((DevicePathType (FilePath) == MESSAGING_DEVICE_PATH) && > + (DevicePathSubType (FilePath) == MSG_URI_DP)) { > + // > + // Expand the URI device path > + // > + return BmExpandUriDevicePath (FilePath, FullPath, FileSize); > } else { > for (Node = FilePath; !IsDevicePathEnd (Node); Node = > NextDevicePathNode (Node)) { > if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && > -- > 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel