[SCM] kodi-pvr-vdr-vnsi/master: VNSISession: ReadResult() returns std::unique_ptr

tiber-guest at users.alioth.debian.org tiber-guest at users.alioth.debian.org
Sun Feb 28 15:46:49 UTC 2016


The following commit has been merged in the master branch:
commit fa2b8d59db7c34165c053d3f661104993aed150f
Author: Max Kellermann <max at duempel.org>
Date:   Thu Nov 5 22:32:35 2015 +0100

    VNSISession: ReadResult() returns std::unique_ptr
    
    Enforce safe pointer use, which also makes the code exception-safe.
    As a side effect, this fixes a bunch of memory leaks: many callers had
    no "delete" call at all!

diff --git a/src/VNSIAdmin.cpp b/src/VNSIAdmin.cpp
index 5b8dbaf..ebd44ab 100644
--- a/src/VNSIAdmin.cpp
+++ b/src/VNSIAdmin.cpp
@@ -1059,7 +1059,7 @@ bool cVNSIAdmin::OnInit()
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift mode", __FUNCTION__);
       return false;
     }
-    cResponsePacket *resp = ReadResult(&vrp);
+    auto resp = ReadResult(&vrp);
     if (!resp)
     {
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift mode", __FUNCTION__);
@@ -1067,7 +1067,6 @@ bool cVNSIAdmin::OnInit()
     }
     int mode = resp->extract_U32();
     m_spinTimeshiftMode->SetValue(mode);
-    delete resp;
   }
 
   m_spinTimeshiftBufferRam = GUI->Control_getSpin(m_window, CONTROL_SPIN_TIMESHIFT_BUFFER_RAM);
@@ -1086,7 +1085,7 @@ bool cVNSIAdmin::OnInit()
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift buffer size", __FUNCTION__);
       return false;
     }
-    cResponsePacket *resp = ReadResult(&vrp);
+    auto resp = ReadResult(&vrp);
     if (!resp)
     {
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift buffer size", __FUNCTION__);
@@ -1094,7 +1093,6 @@ bool cVNSIAdmin::OnInit()
     }
     int mode = resp->extract_U32();
     m_spinTimeshiftBufferRam->SetValue(mode);
-    delete resp;
   }
   m_spinTimeshiftBufferFile = GUI->Control_getSpin(m_window, CONTROL_SPIN_TIMESHIFT_BUFFER_FILE);
   m_spinTimeshiftBufferFile->Clear();
@@ -1111,7 +1109,7 @@ bool cVNSIAdmin::OnInit()
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift buffer (file) size", __FUNCTION__);
       return false;
     }
-    cResponsePacket *resp = ReadResult(&vrp);
+    auto resp = ReadResult(&vrp);
     if (!resp)
     {
       XBMC->Log(LOG_ERROR, "%s - failed to get timeshift buffer (file) size", __FUNCTION__);
@@ -1119,7 +1117,6 @@ bool cVNSIAdmin::OnInit()
     }
     int mode = resp->extract_U32();
     m_spinTimeshiftBufferFile->SetValue(mode);
-    delete resp;
   }
 
   // channel filters
@@ -1377,17 +1374,15 @@ bool cVNSIAdmin::ConnectOSD()
   if (!vrp.init(VNSI_OSD_CONNECT))
     return false;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return false;
   }
   uint32_t osdWidth = vresp->extract_U32();
   uint32_t osdHeight = vresp->extract_U32();
   if (m_osdRender)
     m_osdRender->SetOSDSize(osdWidth, osdHeight);
-  delete vresp;
 
   return true;
 }
@@ -1411,7 +1406,7 @@ bool cVNSIAdmin::ReadChannelList(bool radio)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -1443,7 +1438,6 @@ bool cVNSIAdmin::ReadChannelList(bool radio)
     m_channels.m_channels.push_back(channel);
     m_channels.m_channelsMap[channel.m_id] = m_channels.m_channels.size() - 1;
   }
-  delete vresp;
 
   return true;
 }
@@ -1462,7 +1456,7 @@ bool cVNSIAdmin::ReadChannelWhitelist(bool radio)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -1478,7 +1472,6 @@ bool cVNSIAdmin::ReadChannelWhitelist(bool radio)
     provider.m_caid = vresp->extract_U32();
     m_channels.m_providerWhitelist.push_back(provider);
   }
-  delete vresp;
 
   return true;
 }
@@ -1505,7 +1498,7 @@ bool cVNSIAdmin::SaveChannelWhitelist(bool radio)
     vrp.add_S32(provider.m_caid);
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -1529,7 +1522,7 @@ bool cVNSIAdmin::ReadChannelBlacklist(bool radio)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -1542,7 +1535,6 @@ bool cVNSIAdmin::ReadChannelBlacklist(bool radio)
     int id = vresp->extract_U32();
     m_channels.m_channelBlacklist.push_back(id);
   }
-  delete vresp;
 
   return true;
 }
@@ -1568,7 +1560,7 @@ bool cVNSIAdmin::SaveChannelBlacklist(bool radio)
     vrp.add_S32(b);
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
diff --git a/src/VNSIChannelScan.cpp b/src/VNSIChannelScan.cpp
index 259066b..9e2e47c 100644
--- a/src/VNSIChannelScan.cpp
+++ b/src/VNSIChannelScan.cpp
@@ -141,7 +141,6 @@ void cVNSIChannelScan::StartScan()
   }
 
   cRequestPacket vrp;
-  cResponsePacket* vresp = NULL;
   uint32_t retCode = VNSI_RET_ERROR;
   if (!vrp.init(VNSI_SCAN_START))                          goto SCANError;
   if (!vrp.add_U32(source))                               goto SCANError;
@@ -158,13 +157,15 @@ void cVNSIChannelScan::StartScan()
   if (!vrp.add_U32(m_spinSatellites->GetValue()))         goto SCANError;
   if (!vrp.add_U32(m_spinATSCType->GetValue()))           goto SCANError;
 
-  vresp = ReadResult(&vrp);
-  if (!vresp)
-    goto SCANError;
+  {
+    auto vresp = ReadResult(&vrp);
+    if (!vresp)
+      goto SCANError;
 
-  retCode = vresp->extract_U32();
-  if (retCode != VNSI_RET_OK)
-    goto SCANError;
+    retCode = vresp->extract_U32();
+    if (retCode != VNSI_RET_OK)
+      goto SCANError;
+  }
 
   return;
 
@@ -182,7 +183,7 @@ void cVNSIChannelScan::StopScan()
   if (!vrp.init(VNSI_SCAN_STOP))
     return;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return;
 
@@ -437,7 +438,7 @@ bool cVNSIChannelScan::ReadCountries()
   if (!vrp.init(VNSI_SCAN_GETCOUNTRIES))
     return false;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return false;
 
@@ -461,7 +462,6 @@ bool cVNSIChannelScan::ReadCountries()
   {
     XBMC->Log(LOG_ERROR, "%s - Return error after reading countries (%i)", __FUNCTION__, retCode);
   }
-  delete vresp;
   return retCode == VNSI_RET_OK;
 }
 
@@ -474,7 +474,7 @@ bool cVNSIChannelScan::ReadSatellites()
   if (!vrp.init(VNSI_SCAN_GETSATELLITES))
     return false;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return false;
 
@@ -494,7 +494,6 @@ bool cVNSIChannelScan::ReadSatellites()
   {
     XBMC->Log(LOG_ERROR, "%s - Return error after reading satellites (%i)", __FUNCTION__, retCode);
   }
-  delete vresp;
   return retCode == VNSI_RET_OK;
 }
 
diff --git a/src/VNSIData.cpp b/src/VNSIData.cpp
index 633e3e3..2584c67 100644
--- a/src/VNSIData.cpp
+++ b/src/VNSIData.cpp
@@ -83,7 +83,7 @@ void cVNSIData::OnReconnect()
   PVR->TriggerRecordingUpdate();
 }
 
-cResponsePacket* cVNSIData::ReadResult(cRequestPacket* vrp)
+std::unique_ptr<cResponsePacket> cVNSIData::ReadResult(cRequestPacket* vrp)
 {
   m_mutex.Lock();
 
@@ -107,7 +107,7 @@ cResponsePacket* cVNSIData::ReadResult(cRequestPacket* vrp)
 
   m_mutex.Lock();
 
-  cResponsePacket* vresp = message.pkt;
+  auto vresp = std::move(message.pkt);
   delete message.event;
 
   m_queue.erase(vrp->getSerial());
@@ -126,7 +126,7 @@ bool cVNSIData::GetDriveSpace(long long *total, long long *used)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -144,7 +144,6 @@ bool cVNSIData::GetDriveSpace(long long *total, long long *used)
   *total *= 1024;
   *used  *= 1024;
 
-  delete vresp;
   return true;
 }
 
@@ -157,7 +156,7 @@ bool cVNSIData::SupportChannelScan()
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -165,7 +164,6 @@ bool cVNSIData::SupportChannelScan()
   }
 
   uint32_t ret = vresp->extract_U32();
-  delete vresp;
   return ret == VNSI_RET_OK ? true : false;
 }
 
@@ -180,7 +178,7 @@ bool cVNSIData::SupportRecordingsUndelete()
       return false;
     }
 
-    cResponsePacket* vresp = ReadResult(&vrp);
+    auto vresp = ReadResult(&vrp);
     if (!vresp)
     {
       XBMC->Log(LOG_INFO, "%s - Can't get response packed", __FUNCTION__);
@@ -188,7 +186,6 @@ bool cVNSIData::SupportRecordingsUndelete()
     }
 
     uint32_t ret = vresp->extract_U32();
-    delete vresp;
     return ret == VNSI_RET_OK ? true : false;
   }
 
@@ -202,7 +199,7 @@ bool cVNSIData::EnableStatusInterface(bool onOff)
   if (!vrp.init(VNSI_ENABLESTATUSINTERFACE)) return false;
   if (!vrp.add_U8(onOff)) return false;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -210,7 +207,6 @@ bool cVNSIData::EnableStatusInterface(bool onOff)
   }
 
   uint32_t ret = vresp->extract_U32();
-  delete vresp;
   return ret == VNSI_RET_OK ? true : false;
 }
 
@@ -223,7 +219,7 @@ int cVNSIData::GetChannelsCount()
     return -1;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -231,8 +227,6 @@ int cVNSIData::GetChannelsCount()
   }
 
   uint32_t count = vresp->extract_U32();
-
-  delete vresp;
   return count;
 }
 
@@ -255,7 +249,7 @@ bool cVNSIData::GetChannelsList(ADDON_HANDLE handle, bool radio)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -292,7 +286,6 @@ bool cVNSIData::GetChannelsList(ADDON_HANDLE handle, bool radio)
     PVR->TransferChannelEntry(handle, &tag);
   }
 
-  delete vresp;
   return true;
 }
 
@@ -310,7 +303,7 @@ bool cVNSIData::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL &channel
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -348,7 +341,6 @@ bool cVNSIData::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL &channel
     free((void*)tag.strEpisodeName);
   }
 
-  delete vresp;
   return true;
 }
 
@@ -364,7 +356,7 @@ int cVNSIData::GetTimersCount()
     return -1;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -373,7 +365,6 @@ int cVNSIData::GetTimersCount()
 
   uint32_t count = vresp->extract_U32();
 
-  delete vresp;
   return count;
 }
 
@@ -390,18 +381,16 @@ PVR_ERROR cVNSIData::GetTimerInfo(unsigned int timernumber, PVR_TIMER &tag)
   if (!vrp.add_U32(timernumber))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
 
   uint32_t returnCode = vresp->extract_U32();
   if (returnCode != VNSI_RET_OK)
   {
-    delete vresp;
     if (returnCode == VNSI_RET_DATAUNKNOWN)
       return PVR_ERROR_FAILED;
     else if (returnCode == VNSI_RET_ERROR)
@@ -432,7 +421,6 @@ PVR_ERROR cVNSIData::GetTimerInfo(unsigned int timernumber, PVR_TIMER &tag)
   char *strTitle = vresp->extract_String();
   strncpy(tag.strTitle, strTitle, sizeof(tag.strTitle) - 1);
 
-  delete vresp;
   return PVR_ERROR_NO_ERROR;
 }
 
@@ -445,10 +433,9 @@ bool cVNSIData::GetTimersList(ADDON_HANDLE handle)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
-    delete vresp;
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
     return false;
   }
@@ -490,7 +477,6 @@ bool cVNSIData::GetTimersList(ADDON_HANDLE handle)
       PVR->TransferTimerEntry(handle, &tag);
     }
   }
-  delete vresp;
   return true;
 }
 
@@ -552,15 +538,13 @@ PVR_ERROR cVNSIData::AddTimer(const PVR_TIMER &timerinfo)
   if (!vrp.add_String(path.c_str()))      return PVR_ERROR_UNKNOWN;
   if (!vrp.add_String(""))                return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
     return PVR_ERROR_UNKNOWN;
   }
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
   if (returnCode == VNSI_RET_DATALOCKED)
     return PVR_ERROR_ALREADY_PRESENT;
   else if (returnCode == VNSI_RET_DATAINVALID)
@@ -583,14 +567,12 @@ PVR_ERROR cVNSIData::DeleteTimer(const PVR_TIMER &timerinfo, bool force)
   if (!vrp.add_U32(force))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
 
   if (returnCode == VNSI_RET_DATALOCKED)
     return PVR_ERROR_FAILED;
@@ -635,14 +617,12 @@ PVR_ERROR cVNSIData::UpdateTimer(const PVR_TIMER &timerinfo)
   if (!vrp.add_String(timerinfo.strTitle))   return PVR_ERROR_UNKNOWN;
   if (!vrp.add_String(""))                return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
   if (returnCode == VNSI_RET_DATAUNKNOWN)
     return PVR_ERROR_FAILED;
   else if (returnCode == VNSI_RET_DATAINVALID)
@@ -662,7 +642,7 @@ int cVNSIData::GetRecordingsCount()
     return -1;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -670,8 +650,6 @@ int cVNSIData::GetRecordingsCount()
   }
 
   uint32_t count = vresp->extract_U32();
-
-  delete vresp;
   return count;
 }
 
@@ -684,7 +662,7 @@ PVR_ERROR cVNSIData::GetRecordingsList(ADDON_HANDLE handle)
     return PVR_ERROR_UNKNOWN;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -723,8 +701,6 @@ PVR_ERROR cVNSIData::GetRecordingsList(ADDON_HANDLE handle)
     PVR->TransferRecordingEntry(handle, &tag);
   }
 
-  delete vresp;
-
   return PVR_ERROR_NO_ERROR;
 }
 
@@ -746,15 +722,13 @@ PVR_ERROR cVNSIData::RenameRecording(const PVR_RECORDING& recinfo, const char* n
   if (!vrp.add_String(newname))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_SERVER_ERROR;
   }
 
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
 
   if(returnCode != 0)
    return PVR_ERROR_FAILED;
@@ -774,15 +748,13 @@ PVR_ERROR cVNSIData::DeleteRecording(const PVR_RECORDING& recinfo)
   if (!vrp.add_U32(atoi(recinfo.strRecordingId)))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
 
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
 
   switch(returnCode)
   {
@@ -814,10 +786,9 @@ PVR_ERROR cVNSIData::GetRecordingEdl(const PVR_RECORDING& recinfo, PVR_EDL_ENTRY
   if (!vrp.add_U32(atoi(recinfo.strRecordingId)))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
 
@@ -831,8 +802,6 @@ PVR_ERROR cVNSIData::GetRecordingEdl(const PVR_RECORDING& recinfo, PVR_EDL_ENTRY
     (*size)++;
   }
 
-  delete vresp;
-
   return PVR_ERROR_NO_ERROR;
 }
 
@@ -845,7 +814,7 @@ int cVNSIData::GetDeletedRecordingsCount()
     return -1;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -853,8 +822,6 @@ int cVNSIData::GetDeletedRecordingsCount()
   }
 
   uint32_t count = vresp->extract_U32();
-
-  delete vresp;
   return count;
 }
 
@@ -867,7 +834,7 @@ PVR_ERROR cVNSIData::GetDeletedRecordingsList(ADDON_HANDLE handle)
     return PVR_ERROR_UNKNOWN;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
   {
     XBMC->Log(LOG_ERROR, "%s - Can't get response packed", __FUNCTION__);
@@ -906,8 +873,6 @@ PVR_ERROR cVNSIData::GetDeletedRecordingsList(ADDON_HANDLE handle)
     PVR->TransferRecordingEntry(handle, &tag);
   }
 
-  delete vresp;
-
   return PVR_ERROR_NO_ERROR;
 }
 
@@ -923,16 +888,13 @@ PVR_ERROR cVNSIData::UndeleteRecording(const PVR_RECORDING& recinfo)
   if (!vrp.add_U32(atoi(recinfo.strRecordingId)))
     return PVR_ERROR_UNKNOWN;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
 
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
-
   switch(returnCode)
   {
     case VNSI_RET_DATALOCKED:
@@ -960,16 +922,13 @@ PVR_ERROR cVNSIData::DeleteAllRecordingsFromTrash()
     return PVR_ERROR_UNKNOWN;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return PVR_ERROR_UNKNOWN;
   }
 
   uint32_t returnCode = vresp->extract_U32();
-  delete vresp;
-
   switch(returnCode)
   {
     case VNSI_RET_DATALOCKED:
@@ -995,7 +954,7 @@ bool cVNSIData::OnResponsePacket(cResponsePacket* pkt)
 
 void *cVNSIData::Process()
 {
-  cResponsePacket* vresp;
+  std::unique_ptr<cResponsePacket> vresp;
 
   while (!IsStopped())
   {
@@ -1020,13 +979,9 @@ void *cVNSIData::Process()
       SMessages::iterator it = m_queue.find(vresp->getRequestID());
       if (it != m_queue.end())
       {
-        it->second.pkt = vresp;
+        it->second.pkt = std::move(vresp);
         it->second.event->Broadcast();
       }
-      else
-      {
-        delete vresp;
-      }
     }
 
     // CHANNEL_STATUS
@@ -1085,16 +1040,13 @@ void *cVNSIData::Process()
         XBMC->Log(LOG_DEBUG, "Server requested Epg update for channel: %d", channel);
         PVR->TriggerEpgUpdate(channel);
       }
-
-      delete vresp;
     }
 
     // UNKOWN CHANNELID
 
-    else if (!OnResponsePacket(vresp))
+    else if (!OnResponsePacket(vresp.get()))
     {
       XBMC->Log(LOG_ERROR, "%s - Rxd a response packet on channel %lu !!", __FUNCTION__, vresp->getChannelID());
-      delete vresp;
     }
   }
   return NULL;
@@ -1114,16 +1066,14 @@ int cVNSIData::GetChannelGroupCount(bool automatic)
     return 0;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return 0;
   }
 
   uint32_t count = vresp->extract_U32();
 
-  delete vresp;
   return count;
 }
 
@@ -1138,10 +1088,9 @@ bool cVNSIData::GetChannelGroupList(ADDON_HANDLE handle, bool bRadio)
 
   vrp.add_U8(bRadio);
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return false;
   }
 
@@ -1158,7 +1107,6 @@ bool cVNSIData::GetChannelGroupList(ADDON_HANDLE handle, bool bRadio)
     PVR->TransferChannelGroup(handle, &tag);
   }
 
-  delete vresp;
   return true;
 }
 
@@ -1175,10 +1123,9 @@ bool cVNSIData::GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GR
   vrp.add_U8(group.bIsRadio);
   vrp.add_U8(1); // filter channels
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (vresp == NULL || vresp->noResponse())
   {
-    delete vresp;
     return false;
   }
 
@@ -1194,6 +1141,5 @@ bool cVNSIData::GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GR
     PVR->TransferChannelGroupMember(handle, &tag);
   }
 
-  delete vresp;
   return true;
 }
diff --git a/src/VNSIData.h b/src/VNSIData.h
index a5e5996..3aa91bc 100644
--- a/src/VNSIData.h
+++ b/src/VNSIData.h
@@ -71,7 +71,7 @@ public:
   PVR_ERROR   DeleteAllRecordingsFromTrash();
   PVR_ERROR   UndeleteAllRecordingsFromTrash();
 
-  cResponsePacket*  ReadResult(cRequestPacket* vrp);
+  std::unique_ptr<cResponsePacket> ReadResult(cRequestPacket* vrp);
 
 protected:
 
@@ -86,7 +86,7 @@ private:
   struct SMessage
   {
     PLATFORM::CEvent *event;
-    cResponsePacket  *pkt;
+    std::unique_ptr<cResponsePacket> pkt;
   };
   typedef std::map<int, SMessage> SMessages;
 
diff --git a/src/VNSIDemux.cpp b/src/VNSIDemux.cpp
index 24bc6c7..4ffef5e 100644
--- a/src/VNSIDemux.cpp
+++ b/src/VNSIDemux.cpp
@@ -67,41 +67,38 @@ DemuxPacket* cVNSIDemux::Read()
     return NULL;
   }
 
-  cResponsePacket *resp = ReadMessage(1000, g_iConnectTimeout * 1000);
+  auto resp = ReadMessage(1000, g_iConnectTimeout * 1000);
 
   if(resp == NULL)
     return PVR->AllocateDemuxPacket(0);
 
   if (resp->getChannelID() != VNSI_CHANNEL_STREAM)
   {
-    delete resp;
     return NULL;
   }
 
   if (resp->getOpCodeID() == VNSI_STREAM_CHANGE)
   {
-    StreamChange(resp);
+    StreamChange(resp.get());
     DemuxPacket* pkt = PVR->AllocateDemuxPacket(0);
     pkt->iStreamId  = DMX_SPECIALID_STREAMCHANGE;
-    delete resp;
     return pkt;
   }
   else if (resp->getOpCodeID() == VNSI_STREAM_STATUS)
   {
-    StreamStatus(resp);
+    StreamStatus(resp.get());
   }
   else if (resp->getOpCodeID() == VNSI_STREAM_SIGNALINFO)
   {
-    StreamSignalInfo(resp);
+    StreamSignalInfo(resp.get());
   }
   else if (resp->getOpCodeID() == VNSI_STREAM_CONTENTINFO)
   {
     // send stream updates only if there are changes
-    if(StreamContentInfo(resp))
+    if(StreamContentInfo(resp.get()))
     {
       DemuxPacket* pkt = PVR->AllocateDemuxPacket(0);
       pkt->iStreamId  = DMX_SPECIALID_STREAMCHANGE;
-      delete resp;
       return pkt;
     }
   }
@@ -120,7 +117,6 @@ DemuxPacket* cVNSIDemux::Read()
       p->dts        = (double)resp->getDTS() * DVD_TIME_BASE / 1000000;
       p->pts        = (double)resp->getPTS() * DVD_TIME_BASE / 1000000;
       p->iStreamId  = iStreamId;
-      delete resp;
 
       XbmcPvrStream *stream = m_streams.GetStreamById(pid);
       xbmc_codec_type_t type = XBMC_CODEC_TYPE_UNKNOWN;
@@ -157,7 +153,6 @@ DemuxPacket* cVNSIDemux::Read()
     m_ReferenceDTS = (double)resp->extract_U64() * DVD_TIME_BASE / 1000000;
   }
 
-  delete resp;
   return PVR->AllocateDemuxPacket(0);
 }
 
@@ -176,7 +171,7 @@ bool cVNSIDemux::SeekTime(int time, bool backwards, double *startpts)
     XBMC->Log(LOG_ERROR, "%s - failed to seek1", __FUNCTION__);
     return false;
   }
-  cResponsePacket *resp = ReadResult(&vrp);
+  auto resp = ReadResult(&vrp);
   if (!resp)
   {
     XBMC->Log(LOG_ERROR, "%s - failed to seek2", __FUNCTION__);
@@ -184,7 +179,6 @@ bool cVNSIDemux::SeekTime(int time, bool backwards, double *startpts)
   }
   uint32_t retCode = resp->extract_U32();
   uint32_t serial = resp->extract_U32();
-  delete resp;
 
   if (retCode == VNSI_RET_OK)
   {
@@ -206,14 +200,13 @@ bool cVNSIDemux::SwitchChannel(const PVR_CHANNEL &channelinfo)
     XBMC->Log(LOG_ERROR, "%s - failed to get timeshift mode", __FUNCTION__);
     return false;
   }
-  cResponsePacket *resp = ReadResult(&vrp1);
+  auto resp = ReadResult(&vrp1);
   if (!resp)
   {
     XBMC->Log(LOG_ERROR, "%s - failed to get timeshift mode", __FUNCTION__);
     return false;
   }
   m_bTimeshift = resp->extract_U32();
-  delete resp;
 
   cRequestPacket vrp2;
   if (!vrp2.init(VNSI_CHANNELSTREAM_OPEN) ||
diff --git a/src/VNSIRecording.cpp b/src/VNSIRecording.cpp
index 389723f..2c59c15 100644
--- a/src/VNSIRecording.cpp
+++ b/src/VNSIRecording.cpp
@@ -55,7 +55,7 @@ bool cVNSIRecording::OpenRecording(const PVR_RECORDING& recinfo)
     return false;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return false;
 
@@ -69,7 +69,6 @@ bool cVNSIRecording::OpenRecording(const PVR_RECORDING& recinfo)
   else
     XBMC->Log(LOG_ERROR, "%s - Can't open recording '%s'", __FUNCTION__, recinfo.strTitle);
 
-  delete vresp;
   return (returnCode == VNSI_RET_OK);
 }
 
@@ -108,7 +107,7 @@ int cVNSIRecording::Read(unsigned char* buf, uint32_t buf_size)
     return 0;
   }
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return -1;
 
@@ -117,13 +116,11 @@ int cVNSIRecording::Read(unsigned char* buf, uint32_t buf_size)
   if (length > buf_size)
   {
     XBMC->Log(LOG_ERROR, "%s: PANIC - Received more bytes as requested", __FUNCTION__);
-    delete vresp;
     return 0;
   }
 
   memcpy(buf, data, length);
   m_currentPlayingRecordPosition += length;
-  delete vresp;
   return length;
 }
 
@@ -187,10 +184,9 @@ void cVNSIRecording::GetLength()
   if (!vrp.init(VNSI_RECSTREAM_GETLENGTH))
     return;
 
-  cResponsePacket* vresp = ReadResult(&vrp);
+  auto vresp = ReadResult(&vrp);
   if (!vresp)
     return;
 
   m_currentPlayingRecordBytes = vresp->extract_U64();
-  delete vresp;
 }
diff --git a/src/VNSISession.cpp b/src/VNSISession.cpp
index e988d4c..7141526 100644
--- a/src/VNSISession.cpp
+++ b/src/VNSISession.cpp
@@ -22,8 +22,6 @@
 #include "VNSISession.h"
 #include "client.h"
 
-#include <memory>
-
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/types.h>
@@ -153,7 +151,7 @@ bool cVNSISession::Login()
   return true;
 }
 
-cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int iDatapacketTimeout /*= 10000*/)
+std::unique_ptr<cResponsePacket> cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int iDatapacketTimeout /*= 10000*/)
 {
   uint32_t channelID = 0;
   uint32_t userDataLength = 0;
@@ -281,7 +279,7 @@ cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int
       vresp->setResponse(userData, userDataLength);
   }
 
-  return vresp;
+  return std::unique_ptr<cResponsePacket>(vresp);
 }
 
 bool cVNSISession::TransmitMessage(cRequestPacket* vrp)
@@ -298,7 +296,7 @@ bool cVNSISession::TransmitMessage(cRequestPacket* vrp)
   return true;
 }
 
-cResponsePacket* cVNSISession::ReadResult(cRequestPacket* vrp)
+std::unique_ptr<cResponsePacket> cVNSISession::ReadResult(cRequestPacket* vrp)
 {
   if(!TransmitMessage(vrp))
   {
@@ -306,7 +304,7 @@ cResponsePacket* cVNSISession::ReadResult(cRequestPacket* vrp)
     return NULL;
   }
 
-  cResponsePacket *pkt = NULL;
+  std::unique_ptr<cResponsePacket> pkt;
 
   while((pkt = ReadMessage()))
   {
@@ -315,8 +313,6 @@ cResponsePacket* cVNSISession::ReadResult(cRequestPacket* vrp)
     {
       return pkt;
     }
-    else
-      delete pkt;
   }
 
   SignalConnectionLost();
@@ -325,13 +321,12 @@ cResponsePacket* cVNSISession::ReadResult(cRequestPacket* vrp)
 
 bool cVNSISession::ReadSuccess(cRequestPacket* vrp)
 {
-  cResponsePacket *pkt = NULL;
+  std::unique_ptr<cResponsePacket> pkt;
   if((pkt = ReadResult(vrp)) == NULL)
   {
     return false;
   }
   uint32_t retCode = pkt->extract_U32();
-  delete pkt;
 
   if(retCode != VNSI_RET_OK)
   {
diff --git a/src/VNSISession.h b/src/VNSISession.h
index 649349c..2ece43d 100644
--- a/src/VNSISession.h
+++ b/src/VNSISession.h
@@ -24,6 +24,7 @@
 #include <string>
 #include "platform/threads/threads.h"
 
+#include <memory>
 
 class cResponsePacket;
 class cRequestPacket;
@@ -43,10 +44,10 @@ public:
   virtual bool      Login();
   virtual void      Close();
 
-  cResponsePacket*  ReadMessage(int iInitialTimeout = 10000, int iDatapacketTimeout = 10000);
+  std::unique_ptr<cResponsePacket> ReadMessage(int iInitialTimeout = 10000, int iDatapacketTimeout = 10000);
   bool              TransmitMessage(cRequestPacket* vrp);
 
-  cResponsePacket*  ReadResult(cRequestPacket* vrp);
+  std::unique_ptr<cResponsePacket> ReadResult(cRequestPacket* vrp);
   bool              ReadSuccess(cRequestPacket* m);
 
   int                GetProtocol() const { return m_protocol; }

-- 
kodi-pvr-vdr-vnsi packaging



More information about the pkg-multimedia-commits mailing list