Skip to content

Memleak when emptying session history and using session-based execute callbacks. #171

Closed
@crouchingtiger

Description

@crouchingtiger

When calling [FFmpegKitConfig clearSessions], only the sessionHistoryList is emptied, leaving sessionHistoryMap to leak and retain a reference to the FFmpegSession.

Sessions history list and map are added at https://github.com/tanersener/ffmpeg-kit/blob/5d11e79fc2734a7c61b741f3a729409a17b212e1/apple/src/FFmpegKitConfig.m#L115

Notably, if you are using session execute callbacks , ffmpeg-kit will continue to leak FFmpegSession objects, even if you set [FFmpegKitConfig setSessionHistorySize:0]. I've noticed this behaviour in previous versions but didn't investigate further at the time and was happy enough to use the global callbacks. My use-case has shifted and I have concurrent ffmpeg sessions running for my application, so I took a further look. This affects asynchronous commands issued on another queue. lldb will not be able to point out any obvious leaks here.

As a test, I issued a sample command to + (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue with non-null, empty blocks. I monitored and waited for the autoreleasepool and took some samples after successful return.

Here's the situation without calling the newly added [FFmpegKitConfig clearSessions]:

Bildschirmfoto 2021-10-06 um 17 53 34

and if you do decide to clear the session list:

Bildschirmfoto 2021-10-06 um 17 45 06

Only if ([sessionHistoryList count] > sessionHistorySize) are entries removed when adding a new session. This means at least 1 session will always linger and leak, replacing the previous reference.

Based off this commit, I added a method call to clear out sessionHistoryMap. I can confirm that in my use-case, my leaks disappear once I call [FFmpegKitConfig clearSessions].

Environment

Platform: [macOS]
Architecture: [x86_64]
Version [v4.5]
Source branch [master, v4.5]
Xcode version [13.0]

Metadata

Metadata

Assignees

Labels

androidAffect Android platformappleAffect Apple platformsbugSomething isn't workingfixed-in-v4.5.1libraryAffects the libraryv4.5Affects v4.5 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions