The usual return-value and memory management checks.  I'm not planning
a test for this module though (it does compile at least on Solaris
2.5)
diff --git a/Modules/termios.c b/Modules/termios.c
index 75f77a5..5dfe57f 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -45,7 +45,7 @@
 		ch = (char)mode.c_cc[i];
 		v = PyString_FromStringAndSize(&ch, 1);
 		if (v == NULL)
-			return NULL;
+			goto err;
 		PyList_SetItem(cc, i, v);
 	}
 
@@ -55,15 +55,17 @@
 	if ((mode.c_lflag & ICANON) == 0) {
 		v = PyInt_FromLong((long)mode.c_cc[VMIN]);
 		if (v == NULL)
-			return NULL;
+			goto err;
 		PyList_SetItem(cc, VMIN, v);
 		v = PyInt_FromLong((long)mode.c_cc[VTIME]);
 		if (v == NULL)
-			return NULL;
+			goto err;
 		PyList_SetItem(cc, VTIME, v);
 	}
 
-	v = PyList_New(7);
+	if (!(v = PyList_New(7)))
+		goto err;
+
 	PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
 	PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
 	PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
@@ -71,8 +73,14 @@
 	PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
 	PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
 	PyList_SetItem(v, 6, cc);
-
+	if (PyErr_Occurred()){
+		Py_DECREF(v);
+		goto err;
+	}
 	return v;
+  err:
+	Py_DECREF(cc);
+	return NULL;
 }
 
 /* tcsetattr(fd, when, termios)
@@ -95,11 +103,6 @@
 		PyErr_SetString(PyExc_TypeError, BAD);
 		return NULL;
 	}
-	for (i = 0; i < 6; i++)
-		if (!PyInt_Check(PyList_GetItem(term, i))) {
-			PyErr_SetString(PyExc_TypeError, BAD);
-			return NULL;
-		}
 
 	mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
 	mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
@@ -108,6 +111,8 @@
 	ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
 	ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
 	cc = PyList_GetItem(term, 6);
+	if (PyErr_Occurred())
+		return NULL;
 
 	if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
 		PyErr_SetString(PyExc_TypeError, BAD);
@@ -116,6 +121,7 @@
 
 	for (i = 0; i < NCCS; i++) {
 		v = PyList_GetItem(cc, i);
+
 		if (PyString_Check(v) && PyString_Size(v) == 1)
 			mode.c_cc[i] = (cc_t) * PyString_AsString(v);
 		else if (PyInt_Check(v))