Skip to content

Conversation

@Watson1978
Copy link
Contributor

This PR fixes a potential memory leak in the compression path.

In the current implementation, if zstd_compress returns an error, rb_raise is called immediately. If rb_raise will be called, the subsequent ZSTD_freeCCtx(ctx) is never reached.

This change ensures that ZSTD_freeCCtx(ctx) is called before raising the exception, preventing the context leak. Seems zstd_compress errors are rare in practice, this fix ensures safety for those edge cases.

This PR fixes a potential memory leak in the compression path.

In the current implementation, if zstd_compress returns an error, rb_raise is called immediately.
If rb_raise will be called, the subsequent ZSTD_freeCCtx(ctx) is never reached.

This change ensures that ZSTD_freeCCtx(ctx) is called before raising the exception, preventing the context leak.
Seems zstd_compress errors are rare in practice, this fix ensures safety for those edge cases.
@Watson1978 Watson1978 marked this pull request as draft December 23, 2025 06:15
@Watson1978 Watson1978 marked this pull request as ready for review December 23, 2025 06:22
@Watson1978
Copy link
Contributor Author

I found other memory leak. I will create other PR.

@SpringMT
Copy link
Owner

Thank you!

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