[FFmpeg-devel] avformat/hls.c: Fix memory leak

Valery Kot valery.kot at gmail.com
Mon Dec 17 13:24:13 EET 2018

I just verified that patch is working. Build FFmpeg master with and
without patch, run HLS live stream from Youtube (extracted by
youtube_dl for Euronews live).

ffmpeg -i https://manifest.googlevideo.com/api/manifest/hls_playlist/id/V2E-jOUVsd4.1/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r4---sn-5hnedn7e.googlevideo.com/ei/E2sXXOrRGdjGgAe_6abgBA/gcr/nl/playlist_type/DVR/initcwndbps/12170/mm/32/mn/sn-5hnedn7e/ms/lv/mv/m/pl/24/dover/11/keepalive/yes/mt/1545038545/disable_polymer/true/ip/,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,ei,gcr,playlist_type,initcwndbps,mm,mn,ms,mv,pl/signature/517F67575565239FC2D7117212AB722FB68BA3A6.4A8F847C14BF8C702103AEC348C8AC553E812ECE/key/dg_yt0/playlist/index.m3u8
 -c copy -t 30000 -f mpegts -y NUL 2> _out.txt

Checking process memory (private working set) in Task Manager
Both instances start at 27MB RAM footprint.
Patched version within a minute grows to 31 MB and then stable.
Unmodified master RAM keeps growing, and after one hour reaches 90MB.
Thus 59MB leak in an hour! And keeps growing...

Youtube updates variant playlists app. every 2 seconds, with 3600
fragments each. Means leak of 8(bytes)*3600(pointers in
prev_segments)*30*60(playlists per hour) = 54M - correlates with
experimental results.
Of course, youtube is an extreme case, but leak also degrades over
time any live HLS input.

Please review.

More information about the ffmpeg-devel mailing list