[SCM] kodi-pvr-vdr-vnsi/master: responsepacket: extract_String() returns pointer into userData buffer

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


The following commit has been merged in the master branch:
commit 7602b646f261bab51dcf70b69b11d720c73e265b
Author: Max Kellermann <max at duempel.org>
Date:   Wed Nov 4 20:59:39 2015 +0100

    responsepacket: extract_String() returns pointer into userData buffer
    
    Since userData contains a null-terminated string, there's no reason to
    allocate and copy the buffer; let's just return a pointer into the
    existing buffer.
    
    As a side effect, this fixes a few memory leaks that occur because
    some extract_String() callers do not care for freeing the return
    value.

diff --git a/src/VNSIAdmin.cpp b/src/VNSIAdmin.cpp
index cafb82f..f1a9610 100644
--- a/src/VNSIAdmin.cpp
+++ b/src/VNSIAdmin.cpp
@@ -1443,9 +1443,6 @@ bool cVNSIAdmin::ReadChannelList(bool radio)
     }
     channel.m_radio       = radio;
 
-    delete[] strChannelName;
-    delete[] strProviderName;
-    delete[] strCaids;
     m_channels.m_channels.push_back(channel);
     m_channels.m_channelsMap[channel.m_id] = m_channels.m_channels.size() - 1;
   }
@@ -1483,7 +1480,6 @@ bool cVNSIAdmin::ReadChannelWhitelist(bool radio)
     provider.m_name = strProviderName;
     provider.m_caid = vresp->extract_U32();
     m_channels.m_providerWhitelist.push_back(provider);
-    delete [] strProviderName;
   }
   delete vresp;
 
diff --git a/src/VNSIChannelScan.cpp b/src/VNSIChannelScan.cpp
index 72845ea..dbba8b0 100644
--- a/src/VNSIChannelScan.cpp
+++ b/src/VNSIChannelScan.cpp
@@ -453,9 +453,6 @@ bool cVNSIChannelScan::ReadCountries()
       m_spinCountries->AddLabel(longName, index);
       if (dvdlang == isoName)
         startIndex = index;
-
-      delete[] longName;
-      delete[] isoName;
     }
     if (startIndex >= 0)
       m_spinCountries->SetValue(startIndex);
@@ -490,8 +487,6 @@ bool cVNSIChannelScan::ReadSatellites()
       const char *shortName = vresp->extract_String();
       const char *longName  = vresp->extract_String();
       m_spinSatellites->AddLabel(longName, index);
-      delete[] longName;
-      delete[] shortName;
     }
     m_spinSatellites->SetValue(6);      /* default to Astra 19.2         */
   }
@@ -539,13 +534,11 @@ bool cVNSIChannelScan::OnResponsePacket(cResponsePacket* resp)
   {
     char* str = resp->extract_String();
     m_window->SetControlLabel(LABEL_DEVICE, str);
-    delete[] str;
   }
   else if (requestID == VNSI_SCANNER_TRANSPONDER)
   {
     char* str = resp->extract_String();
     m_window->SetControlLabel(LABEL_TRANSPONDER, str);
-    delete[] str;
   }
   else if (requestID == VNSI_SCANNER_NEWCHANNEL)
   {
@@ -564,8 +557,6 @@ bool cVNSIChannelScan::OnResponsePacket(cResponsePacket* resp)
 
     m_window->AddItem(item, 0);
     GUI->ListItem_destroy(item);
-
-    delete[] str;
   }
   else if (requestID == VNSI_SCANNER_FINISHED)
   {
diff --git a/src/VNSIData.cpp b/src/VNSIData.cpp
index 2710c96..97a79a0 100644
--- a/src/VNSIData.cpp
+++ b/src/VNSIData.cpp
@@ -290,9 +290,6 @@ bool cVNSIData::GetChannelsList(ADDON_HANDLE handle, bool radio)
     tag.bIsRadio          = radio;
 
     PVR->TransferChannelEntry(handle, &tag);
-    delete[] strChannelName;
-    delete[] strProviderName;
-    delete[] strCaids;
   }
 
   delete vresp;
@@ -348,9 +345,6 @@ bool cVNSIData::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL &channel
     tag.iFlags              = EPG_TAG_FLAG_UNDEFINED;
 
     PVR->TransferEpgEntry(handle, &tag);
-    delete[] tag.strTitle;
-    delete[] tag.strPlotOutline;
-    delete[] tag.strPlot;
     free((void*)tag.strEpisodeName);
   }
 
@@ -437,7 +431,6 @@ PVR_ERROR cVNSIData::GetTimerInfo(unsigned int timernumber, PVR_TIMER &tag)
   tag.iWeekdays         = vresp->extract_U32();
   char *strTitle = vresp->extract_String();
   strncpy(tag.strTitle, strTitle, sizeof(tag.strTitle) - 1);
-  delete[] strTitle;
 
   delete vresp;
   return PVR_ERROR_NO_ERROR;
@@ -495,8 +488,6 @@ bool cVNSIData::GetTimersList(ADDON_HANDLE handle)
       tag.iMarginEnd        = 0;
 
       PVR->TransferTimerEntry(handle, &tag);
-
-      delete[] strTitle;
     }
   }
   delete vresp;
@@ -730,12 +721,6 @@ PVR_ERROR cVNSIData::GetRecordingsList(ADDON_HANDLE handle)
     strncpy(tag.strRecordingId, strRecordingId.c_str(), sizeof(tag.strRecordingId) - 1);
 
     PVR->TransferRecordingEntry(handle, &tag);
-
-    delete[] strChannelName;
-    delete[] strTitle;
-    delete[] strPlotOutline;
-    delete[] strPlot;
-    delete[] strDirectory;
   }
 
   delete vresp;
@@ -918,12 +903,6 @@ PVR_ERROR cVNSIData::GetDeletedRecordingsList(ADDON_HANDLE handle)
     strncpy(tag.strRecordingId, strRecordingId.c_str(), sizeof(tag.strRecordingId) - 1);
 
     PVR->TransferRecordingEntry(handle, &tag);
-
-    delete[] strChannelName;
-    delete[] strTitle;
-    delete[] strPlotOutline;
-    delete[] strPlot;
-    delete[] strDirectory;
   }
 
   delete vresp;
@@ -1071,7 +1050,6 @@ void *cVNSIData::Process()
         else
           XBMC->QueueNotification(QUEUE_INFO, strMessageTranslated);
 
-        delete[] msgstr;
         if (g_bCharsetConv)
           XBMC->FreeString(strMessageTranslated);
       }
@@ -1084,9 +1062,6 @@ void *cVNSIData::Process()
 
 //        PVR->Recording(str1, str2, on!=0?true:false);
         PVR->TriggerTimerUpdate();
-
-        delete[] str1;
-        delete[] str2;
       }
       else if (vresp->getRequestID() == VNSI_STATUS_TIMERCHANGE)
       {
@@ -1180,8 +1155,6 @@ bool cVNSIData::GetChannelGroupList(ADDON_HANDLE handle, bool bRadio)
     tag.iPosition = 0;
 
     PVR->TransferChannelGroup(handle, &tag);
-
-    delete[] strGroupName;
   }
 
   delete vresp;
diff --git a/src/VNSIDemux.cpp b/src/VNSIDemux.cpp
index 89ca77c..fda3c07 100644
--- a/src/VNSIDemux.cpp
+++ b/src/VNSIDemux.cpp
@@ -340,8 +340,6 @@ void cVNSIDemux::StreamChange(cResponsePacket *resp)
       newStream.iIdentifier     = (composition_id & 0xffff) | ((ancillary_id & 0xffff) << 16);
 
       newStreams.push_back(newStream);
-
-      delete[] language;
     }
     else if (codecId.Codec().codec_type == XBMC_CODEC_TYPE_RDS)
     {
@@ -354,17 +352,12 @@ void cVNSIDemux::StreamChange(cResponsePacket *resp)
       newStream.iIdentifier     = -1;
 
       newStreams.push_back(newStream);
-
-      delete[] language;
     }
     else
     {
       m_streams.Clear();
-      delete[] type;
       return;
     }
-
-    delete[] type;
   }
 
   m_streams.UpdateStreams(newStreams);
@@ -378,7 +371,6 @@ void cVNSIDemux::StreamStatus(cResponsePacket *resp)
     XBMC->Log(LOG_DEBUG, "%s - %s", __FUNCTION__, status);
     XBMC->QueueNotification(QUEUE_INFO, status);
   }
-  delete[] status;
 }
 
 void cVNSIDemux::StreamSignalInfo(cResponsePacket *resp)
@@ -392,9 +384,6 @@ void cVNSIDemux::StreamSignalInfo(cResponsePacket *resp)
   m_Quality.fe_signal = resp->extract_U32();
   m_Quality.fe_ber    = resp->extract_U32();
   m_Quality.fe_unc    = resp->extract_U32();
-
-  delete[] name;
-  delete[] status;
 }
 
 bool cVNSIDemux::StreamContentInfo(cResponsePacket *resp)
@@ -419,8 +408,6 @@ bool cVNSIDemux::StreamContentInfo(cResponsePacket *resp)
         props->strLanguage[1]     = language[1];
         props->strLanguage[2]     = language[2];
         props->strLanguage[3]     = 0;
-
-        delete[] language;
       }
       else if (props->iCodecType == XBMC_CODEC_TYPE_VIDEO)
       {
@@ -441,8 +428,6 @@ bool cVNSIDemux::StreamContentInfo(cResponsePacket *resp)
         props->strLanguage[1] = language[1];
         props->strLanguage[2] = language[2];
         props->strLanguage[3] = 0;
-
-        delete[] language;
       }
     }
     else
diff --git a/src/VNSISession.cpp b/src/VNSISession.cpp
index 508b761..ea33677 100644
--- a/src/VNSISession.cpp
+++ b/src/VNSISession.cpp
@@ -138,9 +138,6 @@ bool cVNSISession::Login()
       XBMC->Log(LOG_NOTICE, "Logged in at '%lu+%i' to '%s' Version: '%s' with protocol version '%d'",
         vdrTime, vdrTimeOffset, ServerName, ServerVersion, protocol);
 
-    delete[] ServerName;
-    delete[] ServerVersion;
-
     delete vresp;
   }
   catch (const char * str)
diff --git a/src/responsepacket.cpp b/src/responsepacket.cpp
index 31059b3..9191b63 100644
--- a/src/responsepacket.cpp
+++ b/src/responsepacket.cpp
@@ -164,17 +164,15 @@ char* cResponsePacket::extract_String()
 {
   if (serverError()) return NULL;
 
-  const char *p = (const char *)&userData[packetPos];
+  char *p = (char *)&userData[packetPos];
   const char *end = (const char *)memchr(p, '\0', userDataLength - packetPos);
   if (end == NULL)
     /* string is not terminated - fail */
     return NULL;
 
   int length = end - p;
-  char* str = new char[length + 1];
-  strcpy(str, (char*)&userData[packetPos]);
   packetPos += length + 1;
-  return str;
+  return p;
 }
 
 uint8_t cResponsePacket::extract_U8()

-- 
kodi-pvr-vdr-vnsi packaging



More information about the pkg-multimedia-commits mailing list