--- Compress-LZF/LZF.xs 2015/06/28 18:18:03 1.33 +++ Compress-LZF/LZF.xs 2015/06/29 23:51:28 1.34 @@ -37,7 +37,7 @@ static SV * compress_sv (SV *data, char cprepend, int uprepend, int best) { - LZF_STATE *state; + void *state; STRLEN usize, csize; char *src = (char *)SvPVbyte (data, usize); @@ -95,18 +95,23 @@ else croak ("compress can only compress up to %ld bytes", 0x7fffffffL); - New (0, state, 1, LZF_STATE); + if (usize > 2000) perlinterp_release (); + + state = malloc (best ? sizeof (LZF_STATE_BEST) : sizeof (LZF_STATE)); if (!state) - croak ("Compress::LZF unable to allocate memory for compression state"); + { + if (usize > 2000) perlinterp_acquire (); + croak ("Compress::LZF unable to allocate memory for compression state"); + } - if (usize > 2000) perlinterp_release (); /* 11 bytes is the smallest compressible string */ csize = usize < 11 ? 0 : - (best ? lzf_compress_best (src, usize, dst + skip, usize - skip) - : lzf_compress (src, usize, dst + skip, usize - skip, *state)); - if (usize > 2000) perlinterp_acquire (); + (best ? lzf_compress_best (src, usize, dst + skip, usize - skip, *(LZF_STATE_BEST *)state) + : lzf_compress (src, usize, dst + skip, usize - skip, *(LZF_STATE *)state)); - Safefree (state); + free (state); + + if (usize > 2000) perlinterp_acquire (); if (csize) {