Skip to content

Close the encoding converter when a GzipFile is freed - #164

Open
mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-gzfile-econv-leak
Open

mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-gzfile-econv-leak

Conversation

@mame

@mame mame commented Oct 24, 2026

Copy link
Copy Markdown
Member

The converter opened for external/internal encoding options was only closed on rewind, so it leaked for every GzipReader and GzipWriter.

  gz = Zlib.gzip("abc")
  opts = {external_encoding: "Shift_JIS", internal_encoding: "UTF-8"}
  300_000.times { Zlib::GzipReader.new(StringIO.new(gz), **opts).close }
  # RSS: 1.3 GB (35 MB without the options)

The converter opened for external/internal encoding options was only
closed on rewind, so it leaked for every GzipReader and GzipWriter.

  gz = Zlib.gzip("abc")
  opts = {external_encoding: "Shift_JIS", internal_encoding: "UTF-8"}
  300_000.times { Zlib::GzipReader.new(StringIO.new(gz), **opts).close }
  # RSS: 1.3 GB (35 MB without the options)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant