Skip to content

Commit 20f4b8c

Browse files
authored
Merge pull request #124 from Watson1978/fix-leak
Fix potential memory leak if zstd_compress fails
2 parents 8ae07a1 + e5039cd commit 20f4b8c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/zstdruby/zstdruby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
3030
char* output_data = RSTRING_PTR(output);
3131

3232
size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
33+
ZSTD_freeCCtx(ctx);
3334
if (ZSTD_isError(ret)) {
3435
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
3536
}
3637
rb_str_resize(output, ret);
3738

38-
ZSTD_freeCCtx(ctx);
3939
return output;
4040
}
4141

0 commit comments

Comments
 (0)