Branch: refs/heads/master
  Home:   https://github.com/tianocore/edk2
  Commit: beafabdae49c873adecdb7511dbebe9d4ff5c8f0
      
https://github.com/tianocore/edk2/commit/beafabdae49c873adecdb7511dbebe9d4ff5c8f0
  Author: Nate DeSimone <[email protected]>
  Date:   2023-08-31 (Thu, 31 Aug 2023)

  Changed paths:
    M MdeModulePkg/Core/Dxe/Hand/Locate.c

  Log Message:
  -----------
  MdeModulePkg: Fix memory leak in LocateHandleBuffer()

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4543
REF: 
https://uefi.org/specs/UEFI/2.10/07_Services_Boot_Services.html#efi-boot-services-locatehandlebuffer

CoreLocateHandleBuffer() can in certain cases, return an
error and not free an allocated buffer. This scenario
occurs if the first call to InternalCoreLocateHandle()
returns success and the second call returns an error.

On a successful return, LocateHandleBuffer() passes
ownership of the buffer to the caller. However, the UEFI
specification is not explicit about what the expected
ownership of this buffer is in the case of an error.
However, it is heavily implied by the code example given
in section 7.3.15 of v2.10 of the UEFI specificaton that
if LocateHandleBuffer() returns a non-successful status
code then the ownership of the buffer does NOT transfer
to the caller. This code example explicitly refrains from
calling FreePool() if LocateHandleBuffer() returns an
error.

>From a practical standpoint, it is logical to assume that
a non-successful status code indicates that no buffer of
handles was ever allocated. Indeed, in most error cases,
LocateHandleBuffer() does not go far enough to get to the
point where a buffer is allocated. Therefore, all existing
users of this API must already be coded to support the case
of a non-successful status code resulting in an invalid
handle buffer being returned. Therefore, this change will
not cause any backwards compatibility issues with existing
code.

In conclusion, this boils down to a fix for a memory leak
that also brings the behavior of our LocateHandleBuffer()
implementation into alignment with the original intentions
of the UEFI specification authors.

Reviewed-by: Michael D Kinney <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Jian J Wang <[email protected]>
Cc: Dandan Bi <[email protected]>
Signed-off-by: Nate DeSimone <[email protected]>




_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to