@@ -1694,25 +1694,30 @@ _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
16941694{
16951695 /* Optional file methods */
16961696 if (_PyObject_LookupAttr (file , & _Py_ID (peek ), & self -> peek ) < 0 ) {
1697- return -1 ;
1697+ goto error ;
16981698 }
16991699 if (_PyObject_LookupAttr (file , & _Py_ID (readinto ), & self -> readinto ) < 0 ) {
1700- return -1 ;
1700+ goto error ;
1701+ }
1702+ if (_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read ) < 0 ) {
1703+ goto error ;
1704+ }
1705+ if (_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline ) < 0 ) {
1706+ goto error ;
17011707 }
1702- (void )_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read );
1703- (void )_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline );
17041708 if (!self -> readline || !self -> read ) {
1705- if (!PyErr_Occurred ()) {
1706- PyErr_SetString (PyExc_TypeError ,
1707- "file must have 'read' and 'readline' attributes" );
1708- }
1709- Py_CLEAR (self -> read );
1710- Py_CLEAR (self -> readinto );
1711- Py_CLEAR (self -> readline );
1712- Py_CLEAR (self -> peek );
1713- return -1 ;
1709+ PyErr_SetString (PyExc_TypeError ,
1710+ "file must have 'read' and 'readline' attributes" );
1711+ goto error ;
17141712 }
17151713 return 0 ;
1714+
1715+ error :
1716+ Py_CLEAR (self -> read );
1717+ Py_CLEAR (self -> readinto );
1718+ Py_CLEAR (self -> readline );
1719+ Py_CLEAR (self -> peek );
1720+ return -1 ;
17161721}
17171722
17181723/* Returns -1 (with an exception set) on failure, 0 on success. This may
0 commit comments