@@ -594,7 +594,9 @@ Comp_dealloc(compobject *self)
594594{
595595 if (self -> is_initialised && self -> level_buf != NULL )
596596 PyMem_Free (self -> level_buf );
597- PyThread_free_lock (self -> lock );
597+ if (self -> lock != NULL ) {
598+ PyThread_free_lock (self -> lock );
599+ }
598600 Py_XDECREF (self -> zdict );
599601 Py_TYPE (self )-> tp_free ((PyObject * )self );
600602}
@@ -639,7 +641,9 @@ typedef struct
639641static void
640642Decomp_dealloc (decompobject * self )
641643{
642- PyThread_free_lock (self -> lock );
644+ if (self -> lock != NULL ) {
645+ PyThread_free_lock (self -> lock );
646+ }
643647 Py_XDECREF (self -> unused_data );
644648 Py_XDECREF (self -> unconsumed_tail );
645649 Py_XDECREF (self -> zdict );
@@ -683,6 +687,9 @@ newdecompobject()
683687 self -> is_initialised = 0 ;
684688 self -> method_set = 0 ;
685689 self -> zdict = NULL ;
690+ // Decomp_dealloc uses these members when initialization fails
691+ self -> unconsumed_tail = NULL ;
692+ self -> lock = NULL ;
686693 self -> unused_data = PyBytes_FromStringAndSize ("" , 0 );
687694 if (self -> unused_data == NULL ) {
688695 Py_DECREF (self );
@@ -693,7 +700,7 @@ newdecompobject()
693700 Py_DECREF (self );
694701 return NULL ;
695702 }
696- self -> lock = PyThread_allocate_lock ();
703+ self -> lock = PyThread_allocate_lock ();
697704 if (self -> lock == NULL ) {
698705 Py_DECREF (self );
699706 PyErr_SetString (PyExc_MemoryError , "Unable to allocate lock" );
@@ -1578,7 +1585,7 @@ static PyGetSetDef Decomp_properties[] = {
15781585
15791586static PyTypeObject IsalZlibDecompType = {
15801587 .tp_name = "isal_zlib.Decompress" ,
1581- .tp_doc = "Object returned by isal_zlib.compressobj ." ,
1588+ .tp_doc = "Object returned by isal_zlib.decompressobj ." ,
15821589 .tp_basicsize = sizeof (decompobject ),
15831590 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION ,
15841591 .tp_dealloc = (destructor )Decomp_dealloc ,
@@ -1845,6 +1852,9 @@ GzipReader_read_into_buffer(GzipReader *self, uint8_t *out_buffer, size_t out_bu
18451852 if (!(magic1 == 0x1f && magic2 == 0x8b )) {
18461853 Py_BLOCK_THREADS ;
18471854 PyObject * magic_obj = PyBytes_FromStringAndSize ((char * )current_pos , 2 );
1855+ if (magic_obj == NULL ) {
1856+ return -1 ;
1857+ }
18481858 raise_bad_gzip_file (
18491859 "Not a gzipped file (%R)" ,
18501860 magic_obj );
0 commit comments