Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,9 @@ gzfile_free(void *p)
}
zstream_finalize(z);
}
if (gz->ec) {
rb_econv_close(gz->ec);
}
xfree(gz);
}

Expand Down
10 changes: 10 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,16 @@ def test_gunzip_no_memory_leak
};
end

def test_gzip_reader_encoding_conversion_no_memory_leak
assert_no_memory_leak(%W[-r#{LOADED_ZLIB} -rstringio], "#{<<~"{#"}", "#{<<~'};'}", rss: true)
d = Zlib.gzip("data")
opts = {external_encoding: "Shift_JIS", internal_encoding: "UTF-8"}
10_000.times {Zlib::GzipReader.new(StringIO.new(d), **opts).close}
{#
20_000.times {Zlib::GzipReader.new(StringIO.new(d), **opts).close}
};
end

# Test for signal interrupt bug: Z_BUF_ERROR with avail_out > 0
# This reproduces the issue where thread wakeup during GzipReader operations
# can cause Z_BUF_ERROR to be raised incorrectly
Expand Down
Loading