Repository: xbmc/xbmc
File: xbmc/pvr/PVRPlaybackState.cpp (C++)

Code before:
{
  // Obtain dynamic playback url and properties from the respective pvr client
  const std::shared_ptr<const CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
  if (client)
  {
    CPVRStreamProperties props;

    if (item->IsPVRChannel())
    {
      if (source == PVR_SOURCE::DEFAULT)
        client->StreamClosed();

      client->GetChannelStreamProperties(item->GetPVRChannelInfoTag(), source, props);

      if (props.LivePlaybackAsEPG())
      {
        const std::shared_ptr<CPVREpgInfoTag> epgTag = item->GetPVRChannelInfoTag()->GetEPGNow();
        if (epgTag)
          item = new CFileItem(epgTag);
      }
    }
    else if (item->IsPVRRecording())
    {
      client->GetRecordingStreamProperties(item->GetPVRRecordingInfoTag(), props);
    }
    else if (item->IsEPG())
    {
      client->StreamClosed();
      client->GetEpgTagStreamProperties(item->GetEPGInfoTag(), props);

      if (mode == ContentUtils::PlayMode::CHECK_AUTO_PLAY_NEXT_ITEM)
      {
        if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
                CSettings::SETTING_PVRPLAYBACK_AUTOPLAYNEXTPROGRAMME))
          item->SetProperty("epg_playlist_item", true);
      }
      else if (mode == ContentUtils::PlayMode::PLAY_FROM_HERE)
      {
        item->SetProperty("epg_playlist_item", true);
      }
    }

    if (props.size())
    {
      const std::string url = props.GetStreamURL();
      if (!url.empty())
        item->SetDynPath(url);

      const std::string mime = props.GetStreamMimeType();
      if (!mime.empty())
      {

Review comment (performance):
This introduces a memory leak. You need to delete `item` before assigning it a new value. item is a raw pointer. 

Code after:
{
  // Obtain dynamic playback url and properties from the respective pvr client
  const std::shared_ptr<const CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
  if (client)
  {
    CPVRStreamProperties props;

    if (item->IsPVRChannel())
    {
      if (source == PVR_SOURCE::DEFAULT)
      {
        PVR_ERROR retVal = client->StreamClosed();
        if (retVal != PVR_ERROR_NO_ERROR)
          CLog::LogFC(LOGERROR, LOGPVR, "Client error on call to StreamClosed(): {}",
                      CPVRClient::ToString(retVal));
      }

      client->GetChannelStreamProperties(item->GetPVRChannelInfoTag(), source, props);

      if (props.LivePlaybackAsEPG())
      {
        const std::shared_ptr<CPVREpgInfoTag> epgTag = item->GetPVRChannelInfoTag()->GetEPGNow();
        if (epgTag)
        {
          item = std::make_unique<CFileItem>(epgTag);
        }
      }
    }
    else if (item->IsPVRRecording())
    {
      client->GetRecordingStreamProperties(item->GetPVRRecordingInfoTag(), props);
    }
    else if (item->IsEPG())
    {
      PVR_ERROR retVal = client->StreamClosed();
      if (retVal != PVR_ERROR_NO_ERROR)
        CLog::LogFC(LOGERROR, LOGPVR, "Client error on call to StreamClosed(): {}",
                    CPVRClient::ToString(retVal));

      client->GetEpgTagStreamProperties(item->GetEPGInfoTag(), props);

      if (mode == ContentUtils::PlayMode::CHECK_AUTO_PLAY_NEXT_ITEM)
      {
        if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
                CSettings::SETTING_PVRPLAYBACK_AUTOPLAYNEXTPROGRAMME))
          item->SetProperty("epg_playlist_item", true);
      }
      else if (mode == ContentUtils::PlayMode::PLAY_FROM_HERE)
      {
        item->SetProperty("epg_playlist_item", true);
      }