@@ -412,11 +412,16 @@ cdef class Decompress:
412
412
if err != COMP_OK:
413
413
check_isal_deflate_rc(err)
414
414
self .obuflen = DEF_BUF_SIZE
415
+ self .obuf = < unsigned char * > PyMem_Malloc(self .obuflen * sizeof(char ))
415
416
self .unused_data = b" "
416
417
self .unconsumed_tail = b" "
417
418
self .eof = 0
418
419
self .is_initialised = 1
419
420
421
+ def __dealloc__ (self ):
422
+ if self .obuf is not NULL :
423
+ PyMem_Free(self .obuf)
424
+
420
425
cdef save_unconsumed_input(self , Py_buffer * data):
421
426
cdef Py_ssize_t old_size, new_size, left_size
422
427
cdef bytes new_data
@@ -457,7 +462,6 @@ cdef class Decompress:
457
462
cdef int err
458
463
459
464
# Initialise output buffer
460
- cdef unsigned char * obuf = < unsigned char * > PyMem_Malloc(self .obuflen * sizeof(char ))
461
465
out = []
462
466
463
467
cdef bint last_round = 0
@@ -467,7 +471,7 @@ cdef class Decompress:
467
471
while True :
468
472
arrange_input_buffer(& self .stream, & ibuflen)
469
473
while (self .stream.avail_out == 0 or self .stream.avail_in != 0 ):
470
- self .stream.next_out = obuf # Reset output buffer.
474
+ self .stream.next_out = self . obuf # Reset output buffer.
471
475
if total_bytes >= max_length:
472
476
break
473
477
elif total_bytes + self .obuflen >= max_length:
@@ -486,15 +490,14 @@ cdef class Decompress:
486
490
check_isal_inflate_rc(err)
487
491
bytes_written = prev_avail_out - self .stream.avail_out
488
492
total_bytes += bytes_written
489
- out.append(obuf[:bytes_written])
493
+ out.append(self . obuf[:bytes_written])
490
494
if self .stream.block_state == ISAL_BLOCK_FINISH or last_round:
491
495
break
492
496
if self .stream.block_state == ISAL_BLOCK_FINISH or ibuflen == 0 :
493
497
break
494
498
self .save_unconsumed_input(buffer )
495
499
return b" " .join(out)
496
500
finally :
497
- PyMem_Free(obuf)
498
501
PyBuffer_Release(buffer )
499
502
500
503
def flush (self , Py_ssize_t length = DEF_BUF_SIZE):
0 commit comments