@@ -524,10 +524,12 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
524524 if (d -> eof ) {
525525 FT_ATOMIC_STORE_CHAR_RELAXED (d -> needs_input , 0 );
526526 if (d -> bzs_avail_in_real > 0 ) {
527- Py_XSETREF ( d -> unused_data ,
528- PyBytes_FromStringAndSize ( bzs -> next_in , d -> bzs_avail_in_real ) );
529- if (d -> unused_data == NULL )
527+ PyObject * unused_data = PyBytes_FromStringAndSize (
528+ bzs -> next_in , d -> bzs_avail_in_real );
529+ if (unused_data == NULL ) {
530530 goto error ;
531+ }
532+ Py_XSETREF (d -> unused_data , unused_data );
531533 }
532534 }
533535 else if (d -> bzs_avail_in_real == 0 ) {
@@ -687,12 +689,13 @@ static PyObject *
687689BZ2Decompressor_unused_data_get (PyObject * op , void * Py_UNUSED (ignored ))
688690{
689691 BZ2Decompressor * self = _BZ2Decompressor_CAST (op );
692+ if (!FT_ATOMIC_LOAD_CHAR_RELAXED (self -> eof )) {
693+ return Py_GetConstant (Py_CONSTANT_EMPTY_BYTES );
694+ }
690695 PyMutex_Lock (& self -> mutex );
691- PyObject * result = Py_XNewRef (self -> unused_data );
696+ assert (self -> unused_data != NULL );
697+ PyObject * result = Py_NewRef (self -> unused_data );
692698 PyMutex_Unlock (& self -> mutex );
693- if (result == NULL ) {
694- PyErr_SetString (PyExc_AttributeError , "unused_data" );
695- }
696699 return result ;
697700}
698701
0 commit comments