@@ -356,6 +356,9 @@ _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel)
356356 if (self == NULL ) {
357357 return NULL ;
358358 }
359+ /* Initialize the remaining fields (untouched by PyObject_GC_New()). */
360+ const size_t offset = sizeof (struct { PyObject_HEAD });
361+ memset ((char * )self + offset , 0 , sizeof (* self ) - offset );
359362
360363 self -> lock = PyThread_allocate_lock ();
361364 if (self -> lock == NULL ) {
@@ -364,8 +367,6 @@ _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel)
364367 return NULL ;
365368 }
366369
367- // explicit fields initialization as PyObject_GC_New() does not change them
368- self -> flushed = 0 ;
369370 self -> bzs .opaque = NULL ;
370371 self -> bzs .bzalloc = BZ2_Malloc ;
371372 self -> bzs .bzfree = BZ2_Free ;
@@ -656,11 +657,14 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type)
656657 BZ2Decompressor * self ;
657658 int bzerror ;
658659
659- assert (type != NULL && type -> tp_alloc != NULL );
660+ assert (type != NULL );
660661 self = PyObject_GC_New (BZ2Decompressor , type );
661662 if (self == NULL ) {
662663 return NULL ;
663664 }
665+ /* Initialize the remaining fields (untouched by PyObject_GC_New()). */
666+ const size_t offset = sizeof (struct { PyObject_HEAD });
667+ memset ((char * )self + offset , 0 , sizeof (* self ) - offset );
664668
665669 self -> lock = PyThread_allocate_lock ();
666670 if (self -> lock == NULL ) {
@@ -669,17 +673,11 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type)
669673 return NULL ;
670674 }
671675
672- // explicit fields initialization as PyObject_GC_New() does not change them
673- self -> eof = 0 ;
674676 self -> needs_input = 1 ;
675- self -> bzs_avail_in_real = 0 ;
676- self -> input_buffer = NULL ;
677- self -> input_buffer_size = 0 ;
678677 self -> unused_data = PyBytes_FromStringAndSize (NULL , 0 );
679678 if (self -> unused_data == NULL )
680679 goto error ;
681680
682- self -> bzs = (bz_stream ){.opaque = NULL , .bzalloc = NULL , .bzfree = NULL };
683681 bzerror = BZ2_bzDecompressInit (& self -> bzs , 0 , 0 );
684682 if (catch_bz2_error (bzerror ))
685683 goto error ;
0 commit comments