From 81f94bfd9e9d073b1a85d401adc098460a59e408 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Thu, 22 Dec 2022 18:02:15 +0100 Subject: [PATCH] mediaconverter: fix memory leak If the file has multiple audio or video tracks, only one is converted. But in this case there would be memory leaks of various objects for the other (unused) tracks. Fix this for now by allowing only the first track of each type to be used. Ideally, MediaConverter should allow converting all tracks or selecting which ones to keep. Change-Id: I78c0c31648c80c7760dd68b3b4f64537ad2cee88 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5744 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- src/apps/mediaconverter/MediaConverterApp.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/apps/mediaconverter/MediaConverterApp.cpp b/src/apps/mediaconverter/MediaConverterApp.cpp index 1c3fb32be8..9e668d4258 100644 --- a/src/apps/mediaconverter/MediaConverterApp.cpp +++ b/src/apps/mediaconverter/MediaConverterApp.cpp @@ -378,6 +378,7 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile, int64 audioFrameCount = 0; status_t ret = B_OK; + bool multiTrack = false; int32 tracks = inFile->CountTracks(); for (int32 i = 0; i < tracks && (!outAudTrack || !outVidTrack); i++) { @@ -385,6 +386,10 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile, inFormat.Clear(); inTrack->EncodedFormat(&inFormat); if (inFormat.IsAudio() && (audioCodec != NULL)) { + if (outAudTrack != NULL) { + multiTrack = true; + continue; + } inAudTrack = inTrack; outAudFormat.Clear(); outAudFormat.type = B_MEDIA_RAW_AUDIO; @@ -412,6 +417,10 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile, } } else if (inFormat.IsVideo() && (videoCodec != NULL)) { + if (outVidTrack != NULL) { + multiTrack = true; + continue; + } inVidTrack = inTrack; width = (int32)inFormat.Width(); height = (int32)inFormat.Height(); @@ -499,6 +508,14 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile, ret = B_ERROR; } + if (multiTrack) { + BAlert* alert = new BAlert(B_TRANSLATE("Multi-track file detected"), + B_TRANSLATE("The file has multiple audio or video tracks, only the first one of each will " + "be converted."), + B_TRANSLATE("Understood"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->Go(); + } + if (fCancel) { // don't have any video or audio tracks here, or cancelled printf("MediaConverterApp::_ConvertFile()"