diff options
author | fuzzard <fuzzard@users.noreply.github.com> | 2022-12-29 20:08:02 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-29 20:08:02 +1000 |
commit | 077c7888fc58c05f27f061e306068cacb95843d2 (patch) | |
tree | 6b6333500f4111811c0856a6d30bf6828fe05f02 | |
parent | bf1c61e6fc005b0326fa2d10ce61cabc195d6b3f (diff) | |
parent | 418b59bb90c2183320fd07289d51f19981562a8e (diff) |
Merge pull request #22309 from repojohnray/cdemuxstreamfixextradata
[CDemuxStream] fix ExtraData related memory leak
8 files changed, 18 insertions, 22 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h index 07b9242dc0..f4f71618a4 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h @@ -82,14 +82,14 @@ public: source = STREAM_SOURCE_NONE; iDuration = 0; pPrivate = NULL; - ExtraData = NULL; ExtraSize = 0; disabled = false; changes = 0; flags = StreamFlags::FLAG_NONE; } - virtual ~CDemuxStream() { delete[] ExtraData; } + virtual ~CDemuxStream() = default; + CDemuxStream(CDemuxStream&&) = default; virtual std::string GetStreamName(); @@ -105,7 +105,7 @@ public: int iDuration; // in mseconds void* pPrivate; // private pointer for the demuxer - uint8_t* ExtraData; // extra data for codec to use + std::unique_ptr<uint8_t[]> ExtraData; // extra data for codec to use unsigned int ExtraSize; // size of extra data StreamFlags flags; diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxCC.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxCC.cpp index 5aeb9343cf..b91e8e601d 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxCC.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxCC.cpp @@ -319,7 +319,7 @@ void CDVDDemuxCC::Handler(int service, void *userdata) stream.flags = FLAG_HEARING_IMPAIRED; stream.codec = AV_CODEC_ID_TEXT; stream.uniqueId = service; - ctx->m_streams.push_back(stream); + ctx->m_streams.push_back(std::move(stream)); streamdata data; data.streamIdx = idx; diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp index a6f0a8d6d7..2bdc3ea5a9 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp @@ -154,14 +154,12 @@ bool CDVDDemuxClient::ParsePacket(DemuxPacket* pkt) int len = stream->m_parser->parser->split(stream->m_context, pkt->pData, pkt->iSize); if (len > 0 && len < FF_MAX_EXTRADATA_SIZE) { - if (st->ExtraData) - delete[] st->ExtraData; st->changes++; st->disabled = false; st->ExtraSize = len; - st->ExtraData = new uint8_t[len+AV_INPUT_BUFFER_PADDING_SIZE]; - memcpy(st->ExtraData, pkt->pData, len); - memset(st->ExtraData + len, 0 , AV_INPUT_BUFFER_PADDING_SIZE); + st->ExtraData = std::make_unique<uint8_t[]>(len + AV_INPUT_BUFFER_PADDING_SIZE); + memcpy(st->ExtraData.get(), pkt->pData, len); + memset(st->ExtraData.get() + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); stream->m_parser_split = false; change = true; CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - split extradata"); @@ -435,8 +433,7 @@ void CDVDDemuxClient::SetStreamProps(CDemuxStream *stream, std::map<int, std::sh streamAudio->iBitsPerSample = source->iBitsPerSample; if (source->ExtraSize > 0 && source->ExtraData) { - delete[] streamAudio->ExtraData; - streamAudio->ExtraData = new uint8_t[source->ExtraSize]; + streamAudio->ExtraData = std::make_unique<uint8_t[]>(source->ExtraSize); streamAudio->ExtraSize = source->ExtraSize; for (unsigned int j=0; j<source->ExtraSize; j++) streamAudio->ExtraData[j] = source->ExtraData[j]; @@ -476,8 +473,7 @@ void CDVDDemuxClient::SetStreamProps(CDemuxStream *stream, std::map<int, std::sh streamVideo->iBitRate = source->iBitRate; if (source->ExtraSize > 0 && source->ExtraData) { - delete[] streamVideo->ExtraData; - streamVideo->ExtraData = new uint8_t[source->ExtraSize]; + streamVideo->ExtraData = std::make_unique<uint8_t[]>(source->ExtraSize); streamVideo->ExtraSize = source->ExtraSize; for (unsigned int j=0; j<source->ExtraSize; j++) streamVideo->ExtraData[j] = source->ExtraData[j]; @@ -519,8 +515,7 @@ void CDVDDemuxClient::SetStreamProps(CDemuxStream *stream, std::map<int, std::sh if (source->ExtraSize == 4) { - delete[] streamSubtitle->ExtraData; - streamSubtitle->ExtraData = new uint8_t[4]; + streamSubtitle->ExtraData = std::make_unique<uint8_t[]>(4); streamSubtitle->ExtraSize = 4; for (int j=0; j<4; j++) streamSubtitle->ExtraData[j] = source->ExtraData[j]; diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp index fb54673d9e..739bf51922 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp @@ -1880,8 +1880,9 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int streamIdx) if (stream->type != STREAM_NONE && pStream->codecpar->extradata && pStream->codecpar->extradata_size > 0) { stream->ExtraSize = pStream->codecpar->extradata_size; - stream->ExtraData = new uint8_t[pStream->codecpar->extradata_size]; - memcpy(stream->ExtraData, pStream->codecpar->extradata, pStream->codecpar->extradata_size); + stream->ExtraData = std::make_unique<uint8_t[]>(pStream->codecpar->extradata_size); + memcpy(stream->ExtraData.get(), pStream->codecpar->extradata, + pStream->codecpar->extradata_size); } #ifdef HAVE_LIBBLURAY diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp index 5db35cbc6e..5c7ef1bb90 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp @@ -114,8 +114,8 @@ bool CDVDDemuxVobsub::Open(const std::string& filename, int source, const std::s for(unsigned i=0;i<m_Streams.size();i++) { m_Streams[i]->ExtraSize = state.extra.length()+1; - m_Streams[i]->ExtraData = new uint8_t[m_Streams[i]->ExtraSize]; - strcpy((char*)m_Streams[i]->ExtraData, state.extra.c_str()); + m_Streams[i]->ExtraData = std::make_unique<uint8_t[]>(m_Streams[i]->ExtraSize); + strcpy((char*)m_Streams[i]->ExtraData.get(), state.extra.c_str()); } return true; diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp index 52f77ea9cd..b8494e504e 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp @@ -530,7 +530,7 @@ KODI_HANDLE CInputStreamAddon::cb_get_stream_transfer(KODI_HANDLE handle, if (stream->m_ExtraData && stream->m_ExtraSize) { - demuxStream->ExtraData = new uint8_t[stream->m_ExtraSize]; + demuxStream->ExtraData = std::make_unique<uint8_t[]>(stream->m_ExtraSize); demuxStream->ExtraSize = stream->m_ExtraSize; for (unsigned int j = 0; j < stream->m_ExtraSize; ++j) demuxStream->ExtraData[j] = stream->m_ExtraData[j]; diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamPVRBase.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamPVRBase.cpp index b2e49e46a3..03c4bf4de7 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamPVRBase.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamPVRBase.cpp @@ -322,7 +322,7 @@ void CInputStreamPVRBase::UpdateStreamMap() if (stream.iSubtitleInfo) { - streamSubtitle->ExtraData = new uint8_t[4]; + streamSubtitle->ExtraData = std::make_unique<uint8_t[]>(4); streamSubtitle->ExtraSize = 4; streamSubtitle->ExtraData[0] = (stream.iSubtitleInfo >> 8) & 0xff; streamSubtitle->ExtraData[1] = (stream.iSubtitleInfo >> 0) & 0xff; diff --git a/xbmc/cores/VideoPlayer/DVDStreamInfo.cpp b/xbmc/cores/VideoPlayer/DVDStreamInfo.cpp index ffa1a9c74f..f8f7c71943 100644 --- a/xbmc/cores/VideoPlayer/DVDStreamInfo.cpp +++ b/xbmc/cores/VideoPlayer/DVDStreamInfo.cpp @@ -266,7 +266,7 @@ void CDVDStreamInfo::Assign(const CDemuxStream& right, bool withextradata) extradata = malloc(extrasize); if (!extradata) return; - memcpy(extradata, right.ExtraData, extrasize); + memcpy(extradata, right.ExtraData.get(), extrasize); } cryptoSession = right.cryptoSession; |