Skip to content

Commit

Permalink
Don't leak a single AVFrame when getting audio or video properties
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik committed Sep 19, 2024
1 parent 4f64f79 commit 16fdf3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ void LWAudioDecoder::GetAudioProperties(BSAudioProperties &AP) {
av_channel_layout_default(&ch, PropFrame->ch_layout.nb_channels);
AP.ChannelLayout = ch.u.mask;
} else {
av_frame_free(&PropFrame);
throw BestSourceException("Ambisonics and custom channel orders not supported");
}

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

if (AP.AF.Bits <= 0)
av_frame_free(&PropFrame);

if (AP.AF.Bits <= 0) //FIXME, can this still happen?
throw BestSourceException("Codec returned zero size audio");
}

Expand Down
2 changes: 2 additions & 0 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ void LWVideoDecoder::GetVideoProperties(BSVideoProperties &VP) {
VP.Rotation += 360;
}
}

av_frame_free(&PropFrame);
}

AVFrame *LWVideoDecoder::GetNextFrame() {
Expand Down

0 comments on commit 16fdf3e

Please sign in to comment.