Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8614 closed defect (fixed)

FD are not closed when using ffmpeg compiled against mbedtls

Reported by: TotalJustice Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mbedtls
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
After opening any tls connection with ffmpeg compiled against mbedtls, the fd will not be closed after.

I found this bug as i was making a movie player for the Switch (limited open fd at one time), it would eventually crash. I found that I can reproduce this on Linux PC. This bug is not present when compiled against openssl.

I have tried the latest master commit (as of the time and date of submitting).

How to reproduce:
I wrote a short example code. I have commented the effect of the bug with a way to examine the fd not being closed.
https://gist.github.com/ITotalJustice/04275c341a30e028c9eb9873cf1c242f

I hope this helps.

Change History (6)

comment:1 by TotalJustice, 4 years ago

Hi, I fixed the bug, the fd wasn't being closed in the mbedtls close function. I am submitting patch for this.

Should I keep this open until the patch is in the master branch?

comment:2 by mkver, 4 years ago

Yes.

comment:3 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedavformat

The patch did not appear on the development mailing list afaict.

It seems to me the issue is reproducible with the command line interface:

$ valgrind --leak-check=full ./ffmpeg_g -i https://www.radiantmediaplayer.com/media/bbb-360p.mp4 -f null -
==29800== Memcheck, a memory error detector
==29800== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==29800== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==29800== Command: ./ffmpeg_g -i https://www.radiantmediaplayer.com/media/bbb-360p.mp4 -f null -
==29800== 
ffmpeg version N-97301-gf1894c206e Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (SUSE Linux)
  configuration: --enable-mbedtls --enable-version3 --extra-cflags=-I/mnt/sdb6/cehoyos/mbedtls/mbedtls-2.16.5/include/ --extra-ldflags=-L/mnt/sdb6/cehoyos/mbedtls/mbedtls-2.16.5/library
  libavutil      56. 42.102 / 56. 42.102
  libavcodec     58. 78.102 / 58. 78.102
  libavformat    58. 42.100 / 58. 42.100
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.101 /  7. 77.101
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x505a740] st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x505a740] st: 0 edit list 1 Cannot find an index entry before timestamp: 0.                                                      
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://www.radiantmediaplayer.com/media/bbb-360p.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2015-01-22T17:55:18.000000Z
  Duration: 00:01:39.75, start: 0.000000, bitrate: 725 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 640x360 [SAR 1:1 DAR 16:9], 595 kb/s, 24 fps, 24 tbr, 24k tbn, 48 tbc (default)
    Metadata:
      creation_time   : 2015-01-22T17:55:18.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      creation_time   : 2015-01-22T17:55:18.000000Z
      handler_name    : Mainconcept MP4 Sound Media Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':ze=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A    
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf58.42.100
    Stream #0:0(eng): Video: wrapped_avframe, yuv420p(progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 fps, 24 tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2015-01-22T17:55:18.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : Lavc58.78.102 wrapped_avframe
    Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2015-01-22T17:55:18.000000Z
      handler_name    : Mainconcept MP4 Sound Media Handler
      encoder         : Lavc58.78.102 pcm_s16le
frame= 2393 fps= 22 q=-0.0 Lsize=N/A time=00:01:39.75 bitrate=N/A speed=0.902x    
video:1253kB audio:18704kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
==29800== 
==29800== HEAP SUMMARY:
==29800==     in use at exit: 675 bytes in 9 blocks
==29800==   total heap usage: 421,534 allocs, 421,525 frees, 80,833,005 bytes allocated
==29800== 
==29800== 225 (133 direct, 92 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 6
==29800==    at 0x4839EB8: memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29800==    by 0x4839FCE: posix_memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29800==    by 0x118759F: av_malloc (mem.c:87)
==29800==    by 0x118759F: av_mallocz (mem.c:238)
==29800==    by 0x6A5D76: url_alloc_for_protocol (avio.c:95)
==29800==    by 0x6A5D76: ffurl_alloc (avio.c:301)
==29800==    by 0x6A65CE: ffurl_open_whitelist (avio.c:314)
==29800==    by 0x8025DF: ff_tls_open_underlying (tls.c:107)
==29800==    by 0x7B3848: tls_open (tls_mbedtls.c:171)
==29800==    by 0x6A5A8D: ffurl_connect (avio.c:207)
==29800==    by 0x6A6705: ffurl_open_whitelist (avio.c:345)
==29800==    by 0x6EC500: http_open_cnx_internal (http.c:246)
==29800==    by 0x6EC982: http_open_cnx (http.c:273)
==29800==    by 0x6ED0C8: http_open (http.c:590)
==29800== 
==29800== 450 (266 direct, 184 indirect) bytes in 2 blocks are definitely lost in loss record 6 of 6
==29800==    at 0x4839EB8: memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29800==    by 0x4839FCE: posix_memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29800==    by 0x118759F: av_malloc (mem.c:87)
==29800==    by 0x118759F: av_mallocz (mem.c:238)
==29800==    by 0x6A5D76: url_alloc_for_protocol (avio.c:95)
==29800==    by 0x6A5D76: ffurl_alloc (avio.c:301)
==29800==    by 0x6A65CE: ffurl_open_whitelist (avio.c:314)
==29800==    by 0x8025DF: ff_tls_open_underlying (tls.c:107)
==29800==    by 0x7B3848: tls_open (tls_mbedtls.c:171)
==29800==    by 0x6A5A8D: ffurl_connect (avio.c:207)
==29800==    by 0x6A6705: ffurl_open_whitelist (avio.c:345)
==29800==    by 0x6EC500: http_open_cnx_internal (http.c:246)
==29800==    by 0x6EC982: http_open_cnx (http.c:273)
==29800==    by 0x6ECC73: http_seek_internal (http.c:1757)
==29800== 
==29800== LEAK SUMMARY:
==29800==    definitely lost: 399 bytes in 3 blocks
==29800==    indirectly lost: 276 bytes in 6 blocks
==29800==      possibly lost: 0 bytes in 0 blocks
==29800==    still reachable: 0 bytes in 0 blocks
==29800==         suppressed: 0 bytes in 0 blocks
==29800== 
==29800== For lists of detected and suppressed errors, rerun with: -s
==29800== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

comment:5 by Jun Zhao, 4 years ago

Resolution: fixed
Status: newclosed

fixed

Note: See TracTickets for help on using tickets.