/* SEP member function. Deletes an existing section stream */
EFI_STATUS EFIAPI CloseSectionStream(IN UINTN StreamHandleToClose, IN BOOLEAN FreeStreamBuffer)
/* SEP member function. Deletes an existing section stream */
EFI_STATUS EFIAPI CloseSectionStream(IN UINTN StreamHandleToClose, IN BOOLEAN FreeStreamBuffer)
{
  CORE_SECTION_STREAM_NODE  *StreamNode;
  EFI_TPL                   OldTpl;
  EFI_STATUS                Status;
  LIST_ENTRY                *Link;
  CORE_SECTION_CHILD_NODE   *ChildNode;
  OldTpl = CoreRaiseTpl (TPL_NOTIFY);
  Status = FindStreamNode (StreamHandleToClose, &StreamNode);
  if (!EFI_ERROR (Status)) {
    RemoveEntryList (&StreamNode->Link);
    while (!IsListEmpty (&StreamNode->Children)) {
      Link      = GetFirstNode (&StreamNode->Children);
      ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
      FreeChildNode (ChildNode);
    }
    if (FreeStreamBuffer) {
      CoreFreePool (StreamNode->StreamBuffer);
    }
    CoreFreePool (StreamNode);
    Status = EFI_SUCCESS;
  } else {
    Status = EFI_INVALID_PARAMETER;
  }
  CoreRestoreTpl (OldTpl);
  return Status;
}