Skip to content
Merged
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
7 changes: 1 addition & 6 deletions ext/zstdruby/zstdruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
StringValue(input_value);

size_t in_size = RSTRING_LEN(input_value);
const unsigned char *in_r = (const unsigned char *)RSTRING_PTR(input_value);
unsigned char *in = ALLOC_N(unsigned char, in_size);
memcpy(in, in_r, in_size);
const unsigned char *in = (const unsigned char *)RSTRING_PTR(input_value);

size_t off = 0;
const uint32_t ZSTD_MAGIC = 0xFD2FB528U;
Expand All @@ -107,22 +105,19 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
if (magic == ZSTD_MAGIC) {
ZSTD_DCtx *dctx = ZSTD_createDCtx();
if (!dctx) {
xfree(in);
rb_raise(rb_eRuntimeError, "ZSTD_createDCtx failed");
}

VALUE out = decode_one_frame(dctx, in + off, in_size - off, kwargs);

ZSTD_freeDCtx(dctx);
xfree(in);
RB_GC_GUARD(input_value);
return out;
}

off += 1;
}

xfree(in);
RB_GC_GUARD(input_value);
rb_raise(rb_eRuntimeError, "not a zstd frame (magic not found)");
}
Expand Down