Article View: linux.debian.bugs.dist
Article #4389Bug#1153907: src:libgd2: gdImageAvif memory leak in loop (missing upstream PR #832)
From: Yarick
Date: Fri, 13 Nov 2026 15:10
Date: Fri, 13 Nov 2026 15:10
64 lines
4201 bytes
4201 bytes
Package: src:libgd2
Version: 2.3.3-14
Severity: normal
Tags: upstream patch
Forwarded: https://github.com/libgd/libgd/pull/832
Dear Maintainer,
Repeated calls to gdImageAvifCtx() (or imageavif() via PHP bindings) in a loop
result in a continuous, linear leak of native C heap memory (~1.6 MB per call).
Over a batch run of 500-1,000 images, memory accumulates into multiple gigabytes
until the process is killed by the Linux OOM killer. Calling malloc_trim(0) does
not reclaim this memory.
=== Root Cause ===
In src/gd_avif.c, gdImageAvifCtx allocates an avifImage struct:
avifIm = avifImageCreate(gdImageSX(im), gdImageSY(im), 8, subsampling);
In the cleanup block of _gdImageAvifCtx(), avifImageDestroy(avifIm) is missing.
This was reported upstream in libgd/libgd#831 and fixed in upstream PR #832:
https://github.com/libgd/libgd/pull/832
Commit: Fix #831: gdImageAvif memory leak
PHP also backported this into its bundled copy in commit 036bed01ce:
https://github.com/php/php-src/commit/036bed01ce
However, upstream LibGD has not tagged any new release since 2.3.3 (2021).
Because Debian libgd2 (2.3.3-14) is built from the 2.3.3 source tarball,
Debian's libgd.so.3 is missing this fix.
Inspecting the dynamic symbol table of Debian's /usr/lib/x86_64-linux-gnu/libgd.so.3
confirms that avifImageCreate is imported, but avifImageDestroy is absent:
$ objdump -T /usr/lib/x86_64-linux-gnu/libgd.so.3 | grep -i avifImage
0000000000000000 DF *UND* 0000000000000000 Base avifImageYUVToRGB
0000000000000000 DF *UND* 0000000000000000 Base avifImageCreate
0000000000000000 DF *UND* 0000000000000000 Base avifImageRGBToYUV
=== Minimal Reproducer (PHP CLI) ===
<?php
for ($i = 1; $i <= 50; $i++) {
$img = imagecreatetruecolor(800, 800);
$tmp = "/tmp/test_{$i}.avif";
imageavif($img, $tmp, 80);
imagedestroy($img);
@unlink($tmp);
}
During this loop, process Resident Set Size (VmRSS via /proc/self/status) grows
by ~80 MB (~1.6 MB/image) while Zend emalloc stays flat at 2 MB.
By comparison, imagewebp() and imagejpeg() have 0 bytes leaked under identical
conditions.
=== Proposed Fix ===
Please cherry-pick upstream PR #832 into debian/patches for src:libgd2:
https://github.com/libgd/libgd/pull/832
This adds `if (avifIm) avifImageDestroy(avifIm);` to the cleanup block in
src/gd_avif.c.
References:
- Upstream LibGD Issue: https://github.com/libgd/libgd/issues/831
- Upstream LibGD PR: https://github.com/libgd/libgd/pull/832
- PHP Core Issue: https://github.com/php/php-src/issues/25442
Technical Details
Message-ID:
<NZ14B-bEvr-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Yarick <info@slingomama.nl> Newsgroups: linux.debian.bugs.dist Subject: Bug#1153907: src:libgd2: gdImageAvif memory leak in loop (missing upstream PR #832) Date: Fri, 13 Nov 2026 16:10:01 +0100 Message-ID: <NZ14B-bEvr-1@gated-at.bofh.it> X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org Fri Nov 13 15:03:07 2026 Old-Return-Path: <debbugs@buxtehude.debian.org> X-Spam-Flag: NO X-Spam-Score: 0.695 Reply-To: Yarick <yarick75@gmail.com>, info@slingomama.nl, 1153907@bugs.debian.org Resent-To: debian-bugs-dist@lists.debian.org Resent-Cc: team+gd@tracker.debian.org X-Debian-Pr-Message: report 1153907 X-Debian-Pr-Package: src:libgd2 X-Debian-Pr-Keywords: patch upstream X-Debian-Pr-Source: libgd2 User-Agent: Debian Bug Reporter Content-Type: text/plain; charset=UTF-8 X-Greylist: delayed 306 seconds by postgrey-1.37 at buxtehude; Fri, 13 Nov 2026 15:01:24 UTC X-Debian-Message: from BTS X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2002410 List-ID: <debian-bugs-dist.lists.debian.org> List-URL: <https://lists.debian.org/debian-bugs-dist/> Approved: robomod@news.nic.it Lines: 64 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Fri, 13 Nov 2026 15:56:00 +0100 X-Original-Message-ID: <libgd2-avif-leak-20261113@mail.slingomama.nl>