Skip to content

Commit

Permalink
[AdaptiveTree] Fix memory leak when releasing periods
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Jan 16, 2018
1 parent fb0ca21 commit 68ad57b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# inputstream.adaptive (2.1.11)
# inputstream.adaptive (2.1.12)

This is an adaptive file addon for kodi's new InputStream Interface.

Expand Down
2 changes: 1 addition & 1 deletion inputstream.adaptive/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="inputstream.adaptive"
version="2.1.11"
version="2.1.12"
name="InputStream Adaptive"
provider-name="peak3d">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
16 changes: 7 additions & 9 deletions src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,7 @@ namespace adaptive
AdaptiveTree::~AdaptiveTree()
{
for (std::vector<Period*>::const_iterator bp(periods_.begin()), ep(periods_.end()); bp != ep; ++bp)
for (std::vector<AdaptationSet*>::const_iterator ba((*bp)->adaptationSets_.begin()), ea((*bp)->adaptationSets_.end()); ba != ea; ++ba)
for (std::vector<Representation*>::const_iterator br((*ba)->repesentations_.begin()), er((*ba)->repesentations_.end()); br != er; ++br)
if ((*br)->flags_ & Representation::URLSEGMENTS)
{
for (std::vector<Segment>::iterator bs((*br)->segments_.data.begin()), es((*br)->segments_.data.end()); bs != es; ++bs)
delete[] bs->url;
if((*br)->flags_ & Representation::INITIALIZATION)
delete[] (*br)->initialization_.url;
}
delete *bp;

has_timeshift_buffer_ = false;
if (updateThread_)
Expand Down Expand Up @@ -159,9 +151,15 @@ namespace adaptive
Segment seg(*(rep->segments_[pos]));

if (!timestamp)
{
Log(LOGLEVEL_DEBUG, "AdaptiveTree: scale fragment duration: fdur:%u, rep-scale:%u, mov-scale:%u", fragmentDuration, rep->timescale_, movie_timescale);
fragmentDuration = static_cast<std::uint32_t>((static_cast<std::uint64_t>(fragmentDuration)*rep->timescale_) / movie_timescale);
}
else
{
Log(LOGLEVEL_DEBUG, "AdaptiveTree: fragment duration from timestamp: ts:%llu, base:%llu, s-pts:%llu", timestamp, base_time_, seg.startPTS_);
fragmentDuration = static_cast<uint32_t>(timestamp - base_time_ - seg.startPTS_);
}

seg.startPTS_ += fragmentDuration;
seg.range_begin_ += fragmentDuration;
Expand Down
9 changes: 9 additions & 0 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ namespace adaptive
Representation() :bandwidth_(0), samplingRate_(0), width_(0), height_(0), fpsRate_(0), fpsScale_(1), aspect_(0.0f),
flags_(0), hdcpVersion_(0), indexRangeMin_(0), indexRangeMax_(0), channelCount_(0), nalLengthSize_(0), pssh_set_(0), expired_segments_(0),
containerType_(AdaptiveTree::CONTAINERTYPE_MP4), startNumber_(1), nextPts_(0), duration_(0), timescale_(0), current_segment_(nullptr) {};
~Representation() {
if (flags_ & Representation::URLSEGMENTS)
{
for (std::vector<Segment>::iterator bs(segments_.data.begin()), es(segments_.data.end()); bs != es; ++bs)
delete[] bs->url;
if (flags_ & Representation::INITIALIZATION)
delete[]initialization_.url;
}
};
std::string url_;
std::string id;
std::string codecs_;
Expand Down

0 comments on commit 68ad57b

Please sign in to comment.