/* Helper function called as part of the code needed to allocate the proper sized buffer for various EFI interfaces. */
BOOLEAN GrowBuffer(IN OUT EFI_STATUS *Status, IN OUT VOID **Buffer, IN UINTN BufferSize)
/* Helper function called as part of the code needed to allocate the proper sized buffer for various EFI interfaces. */
BOOLEAN GrowBuffer(IN OUT EFI_STATUS *Status, IN OUT VOID **Buffer, IN UINTN BufferSize)
{
  BOOLEAN  TryAgain;
  if ((*Buffer == NULL) && (BufferSize != 0)) {
    *Status = EFI_BUFFER_TOO_SMALL;
  }
  TryAgain = FALSE;
  if (*Status == EFI_BUFFER_TOO_SMALL) {
    if (*Buffer != NULL) {
      FreePool (*Buffer);
    }
    *Buffer = AllocateZeroPool (BufferSize);
    if (*Buffer != NULL) {
      TryAgain = TRUE;
    } else {
      *Status = EFI_OUT_OF_RESOURCES;
    }
  }
  if (!TryAgain && EFI_ERROR (*Status) && (*Buffer != NULL)) {
    FreePool (*Buffer);
    *Buffer = NULL;
  }
  return TryAgain;
}