mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-13 08:06:32 +01:00
Unreported bug: memory and file handle leak when importing custom mpeg...
I could see this on windows: Import a file such as .aiff format, while "Files of type:" reads "FFmpeg-compatible files". Leave Audacity running. Attempt to delete the file in Windows Exploerer. Get a message from Windows that the file is in use by Audacity and cannot be deleted.
This commit is contained in:
@@ -262,6 +262,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<FFmpegContext> mContext; // An object that does proper IO shutdown in its destructor; may be shared with decoder task.
|
||||
AVFormatContext *mFormatContext; //!< Format description, also contains metadata and some useful info
|
||||
int mNumStreams; //!< mNumstreams is less or equal to mFormatContext->nb_streams
|
||||
ScsPtr mScs; //!< Points to array of pointers to stream contexts, which may be shared with a decoder task.
|
||||
@@ -358,12 +359,20 @@ bool FFmpegImportFileHandle::Init()
|
||||
|
||||
av_log_set_callback(av_log_wx_callback);
|
||||
|
||||
int err = ufile_fopen_input(&mFormatContext, mName);
|
||||
if (err < 0)
|
||||
int err;
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : av_open_input_file() failed for file %s"),mName.c_str());
|
||||
return false;
|
||||
std::unique_ptr<FFmpegContext> tempContext;
|
||||
err = ufile_fopen_input(tempContext, mName);
|
||||
if (err < 0)
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : av_open_input_file() failed for file %s"), mName.c_str());
|
||||
return false;
|
||||
}
|
||||
wxASSERT(tempContext.get());
|
||||
// Move from unique to shared pointer
|
||||
mContext.reset(tempContext.release());
|
||||
}
|
||||
mFormatContext = mContext->ic_ptr;
|
||||
|
||||
err = avformat_find_stream_info(mFormatContext, NULL);
|
||||
if (err < 0)
|
||||
@@ -573,7 +582,7 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
|
||||
for (const auto &stream : mChannels) {
|
||||
++s;
|
||||
ODDecodeFFmpegTask* odTask =
|
||||
new ODDecodeFFmpegTask(mScs, ODDecodeFFmpegTask::FromList(mChannels), mFormatContext, s);
|
||||
new ODDecodeFFmpegTask(mScs, ODDecodeFFmpegTask::FromList(mChannels), mContext, s);
|
||||
odTask->CreateFileDecoder(mFilename);
|
||||
|
||||
//each stream has different duration. We need to know it if seeking is to be allowed.
|
||||
@@ -852,21 +861,8 @@ void FFmpegImportFileHandle::GetMetadata(Tags *tags, const wxChar *tag, const ch
|
||||
|
||||
FFmpegImportFileHandle::~FFmpegImportFileHandle()
|
||||
{
|
||||
#ifdef EXPERIMENTAL_OD_FFMPEG
|
||||
//ODDecodeFFmpegTask takes ownership and deltes it there.
|
||||
if(!mUsingOD)
|
||||
{
|
||||
#endif
|
||||
if (FFmpegLibsInst->ValidLibsLoaded())
|
||||
{
|
||||
if (mFormatContext) avformat_close_input(&mFormatContext);
|
||||
av_log_set_callback(av_log_default_callback);
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL_OD_FFMPEG
|
||||
}//mUsingOD
|
||||
#endif
|
||||
|
||||
// Do this before unloading the libraries
|
||||
mContext.reset();
|
||||
|
||||
delete mStreamInfo;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user