Skip to content

Conversation

@Watson1978
Copy link
Contributor

@Watson1978 Watson1978 commented Dec 23, 2025

This PR fixes a memory leak that occurs when a non-string object is passed to Zstd.compress.

If a non-string object was given, StringValue() will raise a TypeError. It causes memory leak.

This patch moves the input validation before the context creation to prevent this leak.

Reproduce

require 'zstd-ruby'

10000.times { Zstd.compress(1234) rescue nil }

This PR fixes a memory leak that occurs when a non-string object is passed to Zstd.compress.

If a non-string object was given, StringValue() will raise a TypeError.
It causes memory leak.

This patch moves the input validation before the context creation to prevent this leak.
@SpringMT
Copy link
Owner

Thank you!

@SpringMT SpringMT merged commit 9804097 into SpringMT:main Dec 23, 2025
7 checks passed
@Watson1978 Watson1978 deleted the fix-leak2 branch December 23, 2025 15:28
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