Skip to content

Free the allocated Pixbuf format name after decoding - #238

Closed
ei-grad wants to merge 1 commit into
Kozea:mainfrom
ei-grad:fix/pixbuf-format-name-leak
Closed

ei-grad wants to merge 1 commit into
Kozea:mainfrom
ei-grad:fix/pixbuf-format-name-leak

Conversation

@ei-grad

@ei-grad ei-grad commented Sep 11, 2026

Copy link
Copy Markdown

Repeated image decoding leaks the C string returned by gdk_pixbuf_format_get_name(): the return value is caller-owned, but decode_to_pixbuf() copies it into Python and drops the original pointer. A long-running Qtile process accumulated approximately 404 MiB of 32-byte allocations containing svg; an isolated 100,000-call reproduction of the format-name conversion increased glibc allocated memory by 3,199,936 bytes.

Declare g_free in the Pixbuf FFI and free the returned name in a finally block after copying it. The returned Python format name is unchanged. Regression tests check that the exact allocated pointer is freed once both on successful decoding and when ASCII decoding raises.

Validation: the two new regression cases fail before the fix and pass afterward; uv run --extra test -m pytest reports 55 passed, 1 skipped (optional XCB dependency unavailable), and uv run --extra test -m ruff check passes.

gdk_pixbuf_format_get_name transfers ownership of its returned string.
Copying it with ffi.string without releasing the original allocation
leaks memory on every image decode, accumulating hundreds of megabytes
in long-running clients that repeatedly render SVG images.

Declare g_free in the Pixbuf FFI and release the name in a finally block
after conversion. Cover both successful conversion and decoding errors
with regression tests that check the allocated pointer is freed once.

Co-Authored-By: Codex CLI <noreply@openai.com>
@grewn0uille

Copy link
Copy Markdown
Member

Hi,

Thanks to follow the contribution guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants