diff options
author | Jøger Hansegård <joger.hansegard@qt.io> | 2023-08-06 22:38:34 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-08-07 15:07:33 +0000 |
commit | 51a6631f485b19d1f3b44abc9ebce16157238ae5 (patch) | |
tree | 29a2396a8491858b3930045598de51db20826fc8 | |
parent | d1febe578dfb72ac76a642d0da58448930a7f873 (diff) |
Fix memory leak and dangling file handle in ffmpeg Encoder
The ffmpeg Encoder was leaving the encoded file open after finalization.
This left the file locked until process termination, and was causing
a memory leak.
The issue prevented deleting files recorded by the 'recorder' sample
application without first closing the application.
Fixes: QTBUG-115810
Change-Id: I4b0ed796c689482e9274e21bd5a1045a62642240
Reviewed-by: Pavel Dubsky <pavel.dubsky@qt.io>
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
(cherry picked from commit 653d90270e576a52d296493038e3ed563075c36f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/multimedia/ffmpeg/qffmpegencoder.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegencoder.cpp b/src/plugins/multimedia/ffmpeg/qffmpegencoder.cpp index 0351cea6a..a64e2a8f3 100644 --- a/src/plugins/multimedia/ffmpeg/qffmpegencoder.cpp +++ b/src/plugins/multimedia/ffmpeg/qffmpegencoder.cpp @@ -57,6 +57,8 @@ Encoder::Encoder(const QMediaEncoderSettings &settings, const QUrl &url) formatContext->url = (char *)av_malloc(encoded.size() + 1); memcpy(formatContext->url, encoded.constData(), encoded.size() + 1); formatContext->pb = nullptr; + + // Initialize the AVIOContext for accessing the resource indicated by the url auto result = avio_open2(&formatContext->pb, formatContext->url, AVIO_FLAG_WRITE, nullptr, nullptr); qCDebug(qLcFFmpegEncoder) << "opened" << result << formatContext->url; @@ -149,6 +151,10 @@ void EncodingFinalizer::run() if (res < 0) qWarning() << "could not write trailer" << res; + // Close the AVIOContext and release any file handles + res = avio_close(encoder->formatContext->pb); + Q_ASSERT(res == 0); + avformat_free_context(encoder->formatContext); qCDebug(qLcFFmpegEncoder) << " done finalizing."; emit encoder->finalizationDone(); |