@@ -45,7 +45,7 @@ termios_tcgetattr(self, args)
4545 ch = (char )mode .c_cc [i ];
4646 v = PyString_FromStringAndSize (& ch , 1 );
4747 if (v == NULL )
48- return NULL ;
48+ goto err ;
4949 PyList_SetItem (cc , i , v );
5050 }
5151
@@ -55,24 +55,32 @@ termios_tcgetattr(self, args)
5555 if ((mode .c_lflag & ICANON ) == 0 ) {
5656 v = PyInt_FromLong ((long )mode .c_cc [VMIN ]);
5757 if (v == NULL )
58- return NULL ;
58+ goto err ;
5959 PyList_SetItem (cc , VMIN , v );
6060 v = PyInt_FromLong ((long )mode .c_cc [VTIME ]);
6161 if (v == NULL )
62- return NULL ;
62+ goto err ;
6363 PyList_SetItem (cc , VTIME , v );
6464 }
6565
66- v = PyList_New (7 );
66+ if (!(v = PyList_New (7 )))
67+ goto err ;
68+
6769 PyList_SetItem (v , 0 , PyInt_FromLong ((long )mode .c_iflag ));
6870 PyList_SetItem (v , 1 , PyInt_FromLong ((long )mode .c_oflag ));
6971 PyList_SetItem (v , 2 , PyInt_FromLong ((long )mode .c_cflag ));
7072 PyList_SetItem (v , 3 , PyInt_FromLong ((long )mode .c_lflag ));
7173 PyList_SetItem (v , 4 , PyInt_FromLong ((long )ispeed ));
7274 PyList_SetItem (v , 5 , PyInt_FromLong ((long )ospeed ));
7375 PyList_SetItem (v , 6 , cc );
74-
76+ if (PyErr_Occurred ()){
77+ Py_DECREF (v );
78+ goto err ;
79+ }
7580 return v ;
81+ err :
82+ Py_DECREF (cc );
83+ return NULL ;
7684}
7785
7886/* tcsetattr(fd, when, termios)
@@ -95,11 +103,6 @@ termios_tcsetattr(self, args)
95103 PyErr_SetString (PyExc_TypeError , BAD );
96104 return NULL ;
97105 }
98- for (i = 0 ; i < 6 ; i ++ )
99- if (!PyInt_Check (PyList_GetItem (term , i ))) {
100- PyErr_SetString (PyExc_TypeError , BAD );
101- return NULL ;
102- }
103106
104107 mode .c_iflag = (tcflag_t ) PyInt_AsLong (PyList_GetItem (term , 0 ));
105108 mode .c_oflag = (tcflag_t ) PyInt_AsLong (PyList_GetItem (term , 1 ));
@@ -108,6 +111,8 @@ termios_tcsetattr(self, args)
108111 ispeed = (speed_t ) PyInt_AsLong (PyList_GetItem (term , 4 ));
109112 ospeed = (speed_t ) PyInt_AsLong (PyList_GetItem (term , 5 ));
110113 cc = PyList_GetItem (term , 6 );
114+ if (PyErr_Occurred ())
115+ return NULL ;
111116
112117 if (!PyList_Check (cc ) || PyList_Size (cc ) != NCCS ) {
113118 PyErr_SetString (PyExc_TypeError , BAD );
@@ -116,6 +121,7 @@ termios_tcsetattr(self, args)
116121
117122 for (i = 0 ; i < NCCS ; i ++ ) {
118123 v = PyList_GetItem (cc , i );
124+
119125 if (PyString_Check (v ) && PyString_Size (v ) == 1 )
120126 mode .c_cc [i ] = (cc_t ) * PyString_AsString (v );
121127 else if (PyInt_Check (v ))
0 commit comments