[x264-devel] x264 memory leaks error at __interceptor_malloc
Dimitry Andric
dimitry at andric.com
Fri Jan 10 17:16:14 UTC 2025
FWIW:
==317551== 166 (136 direct, 30 indirect) bytes in 1 blocks are definitely lost in loss record 230 of 246
==317551== at 0x67C1828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==317551== by 0x2A24731: x264_param_strdup (base.c:220)
==317551== by 0x2A339F6: x264_8_encoder_open (encoder.c:1525)
==317551== by 0x2A29F10: x264_encoder_open_164 (api.c:96)
==317551== by 0xDE2A5B: X264_init (libx264.c:1414)
==317551== by 0xA838D5: avcodec_open2 (avcodec.c:327)
==317551== by 0x2DB7A0: enc_open (ffmpeg_enc.c:322)
==317551== by 0x2FF3DE: enc_open (ffmpeg_sched.c:1666)
==317551== by 0x2FF8AD: send_to_enc (ffmpeg_sched.c:1786)
==317551== by 0x3018F8: sch_filter_send (ffmpeg_sched.c:2452)
==317551== by 0x2E53FC: fg_output_frame (ffmpeg_filter.c:2458)
==317551== by 0x2E59D2: fg_output_step (ffmpeg_filter.c:2559)
It looks like the parameters that are strdup()'d from https://code.videolan.org/videolan/x264/-/blob/master/encoder/encoder.c?ref_type=heads#L1520 onwards never get freed?
For example, when debugging ffmpeg I can see it strdup'ing h->param.rc.psz_stat_out, but there does not seem to be any code that ever frees the psz_stat_out field.
-Dimitry
> On 10 Jan 2025, at 08:19, 丁zhengzheng <xiaozheng.ding399 at gmail.com> wrote:
>
> Summary of the bug:
>
> Hello, dear developers:,
>
> I encountered a memory leak issue #75 <https://code.videolan.org/videolan/x264/-/issues/75> while using FFmpeg with version git master. When I execute configure, if --enable-libx264 and --enable-gpl are enabled, it will trigger a problem. If I don't enable these two options, there won't be any problem. I tried compiling the latest master branch x264 on my own instead of downloading it from Ubuntu, and I was able to reproduce the issue.
>
> The FFmpeg team confirmed that this issue is related to a memory leak in the x264 library, not FFmpeg itself. As suggested by the FFmpeg developers, I am reporting this issue to the x264 team.
>
> Please confirm, I have also contacted the developers of FFmpeg, and here is their response:
>
> <x-msg://14/#byjames10-days-ago>by James, 10 days ago <https://trac.ffmpeg.org/timeline?from=2024-12-20T12%3A55%3A06Z&precision=second>
> Keywords: bugs removed
> Priority:
> important → normal
>
> Resolution:
> → invalid
>
> Status:
> new → closed
>
> This looks like a memleak in libx264, not ffmpeg. x264_encoder_open() fails and apparently doesn't do a proper clean up. You should report it to them.
>
> <x-msg://14/#how-to-reproduce>How to reproduce:
>
> $unzip FFmpeg-master.zip
> $cd FFmpeg-master-dev
> $./configure --enable-libx264 --enable-gpl --cc=clang --cxx=clang++ --toolchain=clang-asan --enable-cross-compile
>
> $make -j 30
> $./ffmpeg -i poc test.mp4
>
> poc <x-msg://14/-/project/536/uploads/34ddfa92d3eacbb3173ed8e9f89fe600/poc>
> <x-msg://14/#crash-log>crash log:
>
> =================================================================
> ==1590113==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 136 byte(s) in 1 object(s) allocated from:
>
> #0 0x5e7e1e17e67e in interceptor_malloc (/home/swift/workstation/github/FFmpeg-master/ffmpeg+0x98067e) (BuildId: 2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b <https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b>)
> #1 <https://trac.ffmpeg.org/ticket/1> 0x731353c0c3d1 (/usr/lib/x86_64-linux-gnu/libx264.so.163+0xc3d1) (BuildId: b2e7160a74448d05d96f3305d73fc2316edbedaf <https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=b2e7160a74448d05d96f3305d73fc2316edbedaf>)
>
> Indirect leak of 30 byte(s) in 2 object(s) allocated from:
>
> #0 0x5e7e1e169083 in interceptor_strdup (/home/swift/workstation/github/FFmpeg-master/ffmpeg+0x96b083) (BuildId: 2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b <https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b>)
> #1 <https://trac.ffmpeg.org/ticket/1> 0x731353c0c353 (/usr/lib/x86_64-linux-gnu/libx264.so.163+0xc353) (BuildId: b2e7160a74448d05d96f3305d73fc2316edbedaf <https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=b2e7160a74448d05d96f3305d73fc2316edbedaf>)
>
> SUMMARY: AddressSanitizer: 166 byte(s) leaked in 3 allocation(s).
>
> <x-msg://14/#ffmpeg-version>ffmpeg version
>
> ffmpeg version 7.1.git Copyright (c) 2000-2024 the FFmpeg developers
> built with Ubuntu clang version 14.0.0-1ubuntu1.1
> configuration: --enable-libx264 --cc=clang --cxx=clang++ --enable-gpl --toolchain=clang-asan
> libavutil 59. 51.100 / 59. 51.100
> libavcodec 61. 27.101 / 61. 27.101
> libavformat 61. 9.101 / 61. 9.101
> libavdevice 61. 4.100 / 61. 4.100
> libavfilter 10. 6.101 / 10. 6.101
> libswscale 8. 12.100 / 8. 12.100
> libswresample 5. 4.100 / 5. 4.100
> libpostproc 58. 4.100 / 58. 4.100
>
> <x-msg://14/#ubuntu-version>ubuntu version
>
> $ lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu 22.04.3 LTS
> Release: 22.04
> Codename: jammy
> $ uname -r
> 6.8.0-49-generic
>
> <x-msg://14/#libx264-version>libx264 version
>
> $ dpkg -s libx264-dev
> Package: libx264-dev
> Status: install ok installed
> Priority: optional
> Section: libdevel
> Installed-Size: 2761
> Maintainer: Ubuntu Developers <ubuntu-devel-discuss at lists.ubuntu.com <mailto:ubuntu-devel-discuss at lists.ubuntu.com>>
> Architecture: amd64
> Multi-Arch: same
> Source: x264
> Version: 2:0.163.3060+git5db6aa6-2build1
> Depends: libx264-163 (= 2:0.163.3060+git5db6aa6-2build1)
> Description: development files for libx264
>
> libx264 is an advanced encoding library for creating H.264 (MPEG-4 AVC)
> video streams.
> .
> This package contains the static library and headers used to build programs
> that use libx264.
>
> Original-Maintainer: Debian Multimedia Maintainers <debian-multimedia at lists.debian.org <mailto:debian-multimedia at lists.debian.org>>
> Homepage: https://www.videolan.org/developers/x264.html
>
> Thanks!
>
> _______________________________________________
> x264-devel mailing list
> x264-devel at videolan.org
> https://mailman.videolan.org/listinfo/x264-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20250110/ddecdfb0/attachment.htm>
More information about the x264-devel
mailing list