Skip to content

Commit 16fdf3e

Browse files
committed
Don't leak a single AVFrame when getting audio or video properties
1 parent 4f64f79 commit 16fdf3e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/audiosource.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,17 @@ void LWAudioDecoder::GetAudioProperties(BSAudioProperties &AP) {
214214
av_channel_layout_default(&ch, PropFrame->ch_layout.nb_channels);
215215
AP.ChannelLayout = ch.u.mask;
216216
} else {
217+
av_frame_free(&PropFrame);
217218
throw BestSourceException("Ambisonics and custom channel orders not supported");
218219
}
219220

220221
AP.NumSamples = (FormatContext->duration * PropFrame->sample_rate) / AV_TIME_BASE - FormatContext->streams[TrackNumber]->codecpar->initial_padding;
221222
if (PropFrame->pts != AV_NOPTS_VALUE)
222223
AP.StartTime = (static_cast<double>(FormatContext->streams[TrackNumber]->time_base.num) * PropFrame->pts) / FormatContext->streams[TrackNumber]->time_base.den;
223224

224-
if (AP.AF.Bits <= 0)
225+
av_frame_free(&PropFrame);
226+
227+
if (AP.AF.Bits <= 0) //FIXME, can this still happen?
225228
throw BestSourceException("Codec returned zero size audio");
226229
}
227230

src/videosource.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ void LWVideoDecoder::GetVideoProperties(BSVideoProperties &VP) {
409409
VP.Rotation += 360;
410410
}
411411
}
412+
413+
av_frame_free(&PropFrame);
412414
}
413415

414416
AVFrame *LWVideoDecoder::GetNextFrame() {

0 commit comments

Comments
 (0)