Skip to content

Commit 9ac8d8e

Browse files
committed
Add back ZSTD_freeCCtx
1 parent c690446 commit 9ac8d8e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

numcodecs/zstd.pyx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,20 @@ def compress(source, int level=DEFAULT_CLEVEL, bint checksum=False):
124124
error = ZSTD_getErrorName(param_set_result)
125125
raise RuntimeError('Could not set zstd checksum flag: %s' % error)
126126

127-
# setup destination
128-
dest_size = ZSTD_compressBound(source_size)
129-
dest = PyBytes_FromStringAndSize(NULL, dest_size)
130-
dest_ptr = PyBytes_AS_STRING(dest)
127+
try:
131128

132-
# perform compression
133-
with nogil:
134-
compressed_size = ZSTD_compress2(cctx, dest_ptr, dest_size, source_ptr, source_size)
129+
# setup destination
130+
dest_size = ZSTD_compressBound(source_size)
131+
dest = PyBytes_FromStringAndSize(NULL, dest_size)
132+
dest_ptr = PyBytes_AS_STRING(dest)
133+
134+
# perform compression
135+
with nogil:
136+
compressed_size = ZSTD_compress2(cctx, dest_ptr, dest_size, source_ptr, source_size)
137+
138+
finally:
139+
if cctx:
140+
ZSTD_freeCCtx(cctx)
135141

136142
# check compression was successful
137143
if ZSTD_isError(compressed_size):

0 commit comments

Comments
 (0)