Skip to content

Commit

Permalink
Fix tiny memory leak if any of the decoder or demuxer options are set…
Browse files Browse the repository at this point in the history
… and opening a file fails
  • Loading branch information
myrsloik committed Sep 21, 2024
1 parent 16fdf3e commit 72c6787
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ void LWAudioDecoder::OpenFile(const std::filesystem::path &SourceFile, int Track
for (const auto &Iter : LAVFOpts)
av_dict_set(&Dict, Iter.first.c_str(), Iter.second.c_str(), 0);

if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0)
if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0) {
av_dict_free(&Dict);
throw BestSourceException("Couldn't open '" + SourceFile.u8string() + "'");
}

av_dict_free(&Dict);

Expand Down
5 changes: 4 additions & 1 deletion src/tracklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "tracklist.h"
#include <cassert>
#include <memory>

extern "C" {
#include <libavformat/avformat.h>
Expand All @@ -31,8 +32,10 @@ void BestTrackList::OpenFile(const std::filesystem::path &SourceFile, const std:
for (const auto &Iter : LAVFOpts)
av_dict_set(&Dict, Iter.first.c_str(), Iter.second.c_str(), 0);

if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0)
if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0) {
av_dict_free(&Dict);
throw BestSourceException("Couldn't open '" + SourceFile.u8string() + "'");
}

av_dict_free(&Dict);

Expand Down
4 changes: 3 additions & 1 deletion src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ void LWVideoDecoder::OpenFile(const std::filesystem::path &SourceFile, const std
for (const auto &Iter : LAVFOpts)
av_dict_set(&Dict, Iter.first.c_str(), Iter.second.c_str(), 0);

if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0)
if (avformat_open_input(&FormatContext, SourceFile.u8string().c_str(), nullptr, &Dict) != 0) {
av_dict_free(&Dict);
throw BestSourceException("Couldn't open '" + SourceFile.u8string() + "'");
}

av_dict_free(&Dict);

Expand Down

0 comments on commit 72c6787

Please sign in to comment.