<div dir="ltr"><p dir="auto">Thanks for confirming the memory leak issue in x264_param_strdup.</p>
<p dir="auto">I understand this might not be a critical issue in typical usage scenarios. However, I'm following up to ask if there are any plans to fix this memory leak in future releases? The fix would be valuable for scenarios like:</p>
<p dir="auto">- Long-running encoding services</p>
<p dir="auto">- Systems with frequent encoder initialization/destruction</p>
<p dir="auto">- Resource-constrained environments</p>
<p dir="auto">Do you have any plans to fix this issue in a future release?<br><br>by 0x20z</p></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Dimitry Andric <<a href="mailto:dimitry@andric.com">dimitry@andric.com</a>> 于2025年1月11日周六 01:16写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>FWIW:<div><br></div><div><div><font face="Menlo">==317551== 166 (136 direct, 30 indirect) bytes in 1 blocks are definitely lost in loss record 230 of 246</font></div><div><font face="Menlo">==317551== at 0x67C1828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)</font></div><div><font face="Menlo">==317551== by 0x2A24731: x264_param_strdup (base.c:220)</font></div><div><font face="Menlo">==317551== by 0x2A339F6: x264_8_encoder_open (encoder.c:1525)</font></div><div><font face="Menlo">==317551== by 0x2A29F10: x264_encoder_open_164 (api.c:96)</font></div><div><font face="Menlo">==317551== by 0xDE2A5B: X264_init (libx264.c:1414)</font></div><div><font face="Menlo">==317551== by 0xA838D5: avcodec_open2 (avcodec.c:327)</font></div><div><font face="Menlo">==317551== by 0x2DB7A0: enc_open (ffmpeg_enc.c:322)</font></div><div><font face="Menlo">==317551== by 0x2FF3DE: enc_open (ffmpeg_sched.c:1666)</font></div><div><font face="Menlo">==317551== by 0x2FF8AD: send_to_enc (ffmpeg_sched.c:1786)</font></div><div><font face="Menlo">==317551== by 0x3018F8: sch_filter_send (ffmpeg_sched.c:2452)</font></div><div><font face="Menlo">==317551== by 0x2E53FC: fg_output_frame (ffmpeg_filter.c:2458)</font></div><div><font face="Menlo">==317551== by 0x2E59D2: fg_output_step (ffmpeg_filter.c:2559)</font></div><div><br></div><div>It looks like the parameters that are strdup()'d from <a href="https://code.videolan.org/videolan/x264/-/blob/master/encoder/encoder.c?ref_type=heads#L1520" target="_blank">https://code.videolan.org/videolan/x264/-/blob/master/encoder/encoder.c?ref_type=heads#L1520</a> onwards never get freed?</div><div><br></div><div>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.</div><div><br></div><div>-Dimitry</div><div><br><blockquote type="cite"><div>On 10 Jan 2025, at 08:19, 丁zhengzheng <<a href="mailto:xiaozheng.ding399@gmail.com" target="_blank">xiaozheng.ding399@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div><h2 dir="auto">Summary of the bug:</h2><p dir="auto">Hello, dear developers:,</p><p dir="auto">I encountered a memory leak issue <a href="https://code.videolan.org/videolan/x264/-/issues/75" target="_blank">#75</a> 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.</p><p dir="auto">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.</p><p dir="auto">Please confirm, I have also contacted the developers of FFmpeg, and here is their response:</p>
<h3 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-byjames10-days-ago"></a>by James, <a href="https://trac.ffmpeg.org/timeline?from=2024-12-20T12%3A55%3A06Z&precision=second" title="See timeline at Dec 20, 2024, 12:55:06 PM" rel="nofollow noreferrer noopener" target="_blank">10 days ago</a>
</h3>
<table dir="auto">
<tbody><tr>
<th align="right">Keywords:</th>
<td>bugs removed</td>
</tr>
<tr>
<th align="right">Priority:</th>
<td><p>important → <strong>normal</strong></p>
</td>
</tr>
<tr>
<th align="right">Resolution:</th>
<td><p>→ <strong>invalid</strong></p>
</td>
</tr>
<tr>
<th align="right">Status:</th>
<td><p>new → <strong>closed</strong></p>
</td>
</tr>
</tbody></table><p dir="auto">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.</p>
<h2 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-how-to-reproduce"></a>How to reproduce:</h2><p dir="auto">$unzip FFmpeg-master.zip<br>
$cd FFmpeg-master-dev<br>
$./configure --enable-libx264 --enable-gpl --cc=clang --cxx=clang++ --toolchain=clang-asan --enable-cross-compile</p><p dir="auto">$make -j 30<br>
$./ffmpeg -i poc test.mp4</p><p dir="auto"><a>poc</a></p>
<h2 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-crash-log"></a>crash log:</h2><p dir="auto">=================================================================<br>
==1590113==ERROR: LeakSanitizer: detected memory leaks</p><p dir="auto">Direct leak of 136 byte(s) in 1 object(s) allocated from:</p>
<blockquote dir="auto"><p>#0 0x5e7e1e17e67e in interceptor_malloc (/home/swift/workstation/github/FFmpeg-master/ffmpeg+0x98067e) (BuildId: <a href="https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b" title="Changeset 2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b" rel="nofollow noreferrer noopener" target="_blank">2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b</a>)<br>
<a href="https://trac.ffmpeg.org/ticket/1" title="#1: task: Test (closed: invalid)" rel="nofollow noreferrer noopener" target="_blank">#1</a> 0x731353c0c3d1 (/usr/lib/x86_64-linux-gnu/libx264.so.163+0xc3d1) (BuildId: <a href="https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=b2e7160a74448d05d96f3305d73fc2316edbedaf" title="Changeset b2e7160a74448d05d96f3305d73fc2316edbedaf" rel="nofollow noreferrer noopener" target="_blank">b2e7160a74448d05d96f3305d73fc2316edbedaf</a>)</p>
</blockquote><p dir="auto">Indirect leak of 30 byte(s) in 2 object(s) allocated from:</p>
<blockquote dir="auto"><p>#0 0x5e7e1e169083 in interceptor_strdup (/home/swift/workstation/github/FFmpeg-master/ffmpeg+0x96b083) (BuildId: <a href="https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b" title="Changeset 2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b" rel="nofollow noreferrer noopener" target="_blank">2e3adc0cc0a1ce7cb06b6662338d6fd012a2a61b</a>)<br>
<a href="https://trac.ffmpeg.org/ticket/1" title="#1: task: Test (closed: invalid)" rel="nofollow noreferrer noopener" target="_blank">#1</a> 0x731353c0c353 (/usr/lib/x86_64-linux-gnu/libx264.so.163+0xc353) (BuildId: <a href="https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=b2e7160a74448d05d96f3305d73fc2316edbedaf" title="Changeset b2e7160a74448d05d96f3305d73fc2316edbedaf" rel="nofollow noreferrer noopener" target="_blank">b2e7160a74448d05d96f3305d73fc2316edbedaf</a>)</p>
</blockquote><p dir="auto">SUMMARY: AddressSanitizer: 166 byte(s) leaked in 3 allocation(s).</p>
<h2 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-ffmpeg-version"></a>ffmpeg version</h2><p dir="auto">ffmpeg version 7.1.git Copyright (c) 2000-2024 the FFmpeg developers<br>
built with Ubuntu clang version 14.0.0-1ubuntu1.1<br>
configuration: --enable-libx264 --cc=clang --cxx=clang++ --enable-gpl --toolchain=clang-asan<br>
libavutil 59. 51.100 / 59. 51.100<br>
libavcodec 61. 27.101 / 61. 27.101<br>
libavformat 61. 9.101 / 61. 9.101<br>
libavdevice 61. 4.100 / 61. 4.100<br>
libavfilter 10. 6.101 / 10. 6.101<br>
libswscale 8. 12.100 / 8. 12.100<br>
libswresample 5. 4.100 / 5. 4.100<br>
libpostproc 58. 4.100 / 58. 4.100</p>
<h2 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-ubuntu-version"></a>ubuntu version</h2><p dir="auto">$ lsb_release -a<br>
No LSB modules are available.<br>
Distributor ID: Ubuntu<br>
Description: Ubuntu 22.04.3 LTS<br>
Release: 22.04<br>
Codename: jammy<br>
$ uname -r<br>
6.8.0-49-generic</p>
<h2 dir="auto">
<a aria-hidden="true" id="m_4683599490618336250gmail-user-content-libx264-version"></a>libx264 version</h2><p dir="auto">$ dpkg -s libx264-dev<br>
Package: libx264-dev<br>
Status: install ok installed<br>
Priority: optional<br>
Section: libdevel<br>
Installed-Size: 2761<br>
Maintainer: Ubuntu Developers <<a href="mailto:ubuntu-devel-discuss@lists.ubuntu.com" target="_blank">ubuntu-devel-discuss@lists.ubuntu.com</a>><br>
Architecture: amd64<br>
Multi-Arch: same<br>
Source: x264<br>
Version: 2:0.163.3060+git5db6aa6-2build1<br>
Depends: libx264-163 (= 2:0.163.3060+git5db6aa6-2build1)<br>
Description: development files for libx264</p>
<blockquote dir="auto"><p>libx264 is an advanced encoding library for creating H.264 (MPEG-4 AVC)<br>
video streams.<br>
.<br>
This package contains the static library and headers used to build programs<br>
that use libx264.</p>
</blockquote><p dir="auto">Original-Maintainer: Debian Multimedia Maintainers <<a href="mailto:debian-multimedia@lists.debian.org" target="_blank">debian-multimedia@lists.debian.org</a>><br>
Homepage: <a href="https://www.videolan.org/developers/x264.html" rel="nofollow noreferrer noopener" target="_blank">https://www.videolan.org/developers/x264.html</a></p><p dir="auto">Thanks!</p></div></div>
_______________________________________________<br>x264-devel mailing list<br><a href="mailto:x264-devel@videolan.org" target="_blank">x264-devel@videolan.org</a><br><a href="https://mailman.videolan.org/listinfo/x264-devel" target="_blank">https://mailman.videolan.org/listinfo/x264-devel</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
x264-devel mailing list<br>
<a href="mailto:x264-devel@videolan.org" target="_blank">x264-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x264-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x264-devel</a><br>
</blockquote></div>