Opened 5 years ago

Closed 4 years ago

#8094 closed defect (fixed)

Memory leaks from realloc

Reported by: Suhwan Owned by:
Priority: minor Component: ffmpeg
Version: git-master Keywords: leak
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:
There is a memory leak from realloc
How to reproduce:

% ./ffmpeg_g  -i audio-gaps.ogg -loglevel 99 -c copy -map 0 -y  -disposition:v:174 a64multi  -c:a:171 a64multi -disposition:s:9 a64multi -stream_loop 24 -t 3 -target vcd -r 82 -ab 907 -ar 22050 -ac 4 -b:v 866k -level 12 -strict 3 tmp.mp4
ffmpeg version git-master
built on ... clang-6.0

ASAN report:

==48423==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 96 byte(s) in 3 object(s) allocated from:
    #0 0x4de8d0 in realloc (ffmpeg_g+0x4de8d0)
    #1 0x5ce398 in grow_array ffmpeg/fftools/cmdutils.c:2163:24

Indirect leak of 34 byte(s) in 6 object(s) allocated from:
    #0 0x4de8d0 in realloc (ffmpeg_g+0x4de8d0)
    #1 0x8500297 in av_realloc ffmpeg/libavutil/mem.c:144:12
    #2 0x8500297 in av_strdup ffmpeg/libavutil/mem.c:256
    #3 0x5b5001 in parse_optgroup ffmpeg/fftools/cmdutils.c:437:15

Indirect leak of 15 byte(s) in 2 object(s) allocated from:
    #0 0x4de8d0 in realloc (ffmpeg_g+0x4de8d0)
    #1 0x8500297 in av_realloc ffmpeg/libavutil/mem.c:144:12
    #2 0x8500297 in av_strdup ffmpeg/libavutil/mem.c:256
    #3 0x5b5001 in parse_optgroup ffmpeg/fftools/cmdutils.c:437:15
    #4 0x69746c756d343660  (<unknown module>)

SUMMARY: AddressSanitizer: 145 byte(s) leaked in 11 allocation(s).

Attachments (2)

debug_report (7.7 KB ) - added by Suhwan 5 years ago.
audio-gaps.ogg (12.0 KB ) - added by Suhwan 5 years ago.
poc

Download all attachments as: .zip

Change History (5)

by Suhwan, 5 years ago

Attachment: debug_report added

comment:1 by Suhwan, 5 years ago

Priority: normalimportant

Valgrind report

 $ valgrind ./ffmpeg_g -i ./samples/ogg/audio-gaps.ogg -loglevel 99 -c copy -map 0 -y -disposition:v:174 a64multi -c:a:171 a64multi -disposition:s:9 a64multi -stream_loop 24 -t 3 -target vcd -r 82 -ab 907 -ar 22050 -ac 4 -b:v 866k -level 12 -strict 3 tmp.mp4
==21685== Memcheck, a memory error detector
==21685== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21685== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==21685== Command: ../ffmpeg/ffmpeg_g -i ./samples/ogg/audio-gaps.ogg -loglevel 99 -c copy -map 0 -y -disposition:v:174 a64multi -c:a:171 a64multi -disposition:s:9 a64multi -stream_loop 24 -t 3 -target vcd -r 82 -ab 907 -ar 22050 -ac 4 -b:v 866k -level 12 -strict 3 tmp.mp4
==21685== 
ffmpeg version N-94906-gcb8d6a4e3e Copyright (c) 2000-2019 the FFmpeg developers
  built with clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
  configuration: --cc=clang --cxx=clang++ --ld=clang --enable-debug --toolchain=clang-usan
  libavutil      56. 35.100 / 56. 35.100
  libavcodec     58. 56.101 / 58. 56.101
  libavformat    58. 32.104 / 58. 32.104
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 58.102 /  7. 58.102
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument './samples/ogg/audio-gaps.ogg'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-disposition:v:174' ... matched as option 'disposition' (disposition) with argument 'a64multi'.
Reading option '-c:a:171' ... matched as option 'c' (codec name) with argument 'a64multi'.
Reading option '-disposition:s:9' ... matched as option 'disposition' (disposition) with argument 'a64multi'.
Reading option '-stream_loop' ... matched as option 'stream_loop' (set number of times input stream shall be looped) with argument '24'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '3'.
Reading option '-target' ... matched as option 'target' (specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")) with argument 'vcd'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '82'.
Reading option '-ab' ... matched as option 'ab' (audio bitrate (please use -b:a)) with argument '907'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '22050'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '4'.
Reading option '-b:v' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '866k'.
Reading option '-level' ... matched as AVOption 'level' with argument '12'.
Reading option '-strict' ...Routing option strict to both codec and muxer layer
 matched as AVOption 'strict' with argument '3'.
Reading option 'tmp.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument 99.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url ./samples/ogg/audio-gaps.ogg.
Successfully parsed a group of options.
Opening an input file: ./samples/ogg/audio-gaps.ogg.
[NULL @ 0x11c4b880] Opening './samples/ogg/audio-gaps.ogg' for reading
[file @ 0x11c4c6c0] Setting default whitelist 'file,crypto'
Probing mp3 score:1 size:2048
Probing ogg score:100 size:2048
[ogg @ 0x11c4b880] Format ogg probed with size=2048 and score=100
[ogg @ 0x11c4b880] ogg_packet: curidx=-1
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=0 psize=0 segp=0 nsegs=1
[ogg @ 0x11c4b880] ogg_packet: curidx=-1
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=30 psize=0 segp=0 nsegs=14
[ogg @ 0x11c4b880] ogg_packet: curidx=0
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=46 psize=0 segp=1 nsegs=14
[ogg @ 0x11c4b880] ogg_packet: curidx=-1
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=3288 psize=0 segp=0 nsegs=19
[ogg @ 0x11c4b880] found headers
[ogg @ 0x11c4b880] ogg_packet: curidx=-1
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=0 psize=0 segp=0 nsegs=19
[ogg @ 0x11c4b880] Before avformat_find_stream_info() pos: 7636 bytes read:12306 seeks:0 nb_streams:1
[ogg @ 0x11c4b880] ogg_packet: curidx=0
[ogg @ 0x11c4b880] ogg_packet: idx=0 pstart=3288 psize=0 segp=0 nsegs=19
[ogg @ 0x11c4b880] All info found
[ogg @ 0x11c4b880] stream 0: start_time: 0.000 duration: 2.301
[ogg @ 0x11c4b880] format: start_time: 0.000 duration: 2.301 bitrate=42 kb/s
[ogg @ 0x11c4b880] After avformat_find_stream_info() pos: 7636 bytes read:12306 seeks:0 frames:1
Input #0, ogg, from './samples/ogg/audio-gaps.ogg':
  Duration: 00:00:02.30, start: 0.000000, bitrate: 42 kb/s
    Stream #0:0, 1, 1/11127: Audio: vorbis, 11127 Hz, stereo, fltp
Successfully opened the file.
Parsing a group of options: output url tmp.mp4.
Applying option c (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0.
Applying option disposition:v:174 (disposition) with argument a64multi.
Applying option c:a:171 (codec name) with argument a64multi.
Applying option disposition:s:9 (disposition) with argument a64multi.
Option stream_loop (set number of times input stream shall be looped) cannot be applied to output url tmp.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for output file tmp.mp4.
Error opening output files: Invalid argument
[AVIOContext @ 0x11c551c0] Statistics: 12306 bytes read, 0 seeks
==21685== 
==21685== HEAP SUMMARY:
==21685==     in use at exit: 177 bytes in 12 blocks
==21685==   total heap usage: 322 allocs, 310 frees, 1,022,052 bytes allocated
==21685== 
==21685== LEAK SUMMARY:
==21685==    definitely lost: 96 bytes in 3 blocks
==21685==    indirectly lost: 49 bytes in 8 blocks
==21685==      possibly lost: 0 bytes in 0 blocks
==21685==    still reachable: 32 bytes in 1 blocks
==21685==         suppressed: 0 bytes in 0 blocks
==21685== Rerun with --leak-check=full to see details of leaked memory
==21685== 
==21685== For counts of detected and suppressed errors, rerun with: -v
==21685== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

by Suhwan, 5 years ago

Attachment: audio-gaps.ogg added

poc

comment:2 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedffmpeg
Keywords: leak added
Priority: importantminor
Reproduced by developer: set
Status: newopen

Not a library leak afaics.

comment:3 by Carl Eugen Hoyos, 4 years ago

Resolution: fixed
Status: openclosed

Fixed by Andreas Rheinhardt in 21265f42ecb265debe9fec1dbfd0cb7de5a8aefb

Note: See TracTickets for help on using tickets.