@@ -73,16 +73,22 @@ int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
73
73
PyObject * field_docs = PyTuple_New (n_members );
74
74
PyStructSequence_Field * fields = desc -> fields ;
75
75
for (i = 0 ; i < n_members ; i ++ ) {
76
- PyTuple_SetItem (field_names , i , polyglot_from_string (fields [i ].name , SRC_CS ));
77
- PyTuple_SetItem (field_docs , i , polyglot_from_string (fields [i ].doc , SRC_CS ));
76
+ PyTuple_SetItem (field_names , i , polyglot_from_string (fields [i ].name , SRC_CS ));
77
+ PyTuple_SetItem (field_docs , i , polyglot_from_string (fields [i ].doc , SRC_CS ));
78
78
}
79
79
80
80
// we create the new type managed
81
81
PyTypeObject * newType = (PyTypeObject * ) UPCALL_CEXT_O (_jls_PyStructSequence_InitType2 ,
82
- polyglot_from_string (desc -> name , SRC_CS ),
83
- polyglot_from_string (desc -> doc , SRC_CS ),
84
- native_to_java (field_names ),
85
- native_to_java (field_docs ));
82
+ polyglot_from_string (desc -> name , SRC_CS ),
83
+ polyglot_from_string (desc -> doc , SRC_CS ),
84
+ native_to_java (field_names ),
85
+ native_to_java (field_docs ));
86
+
87
+ if (newType == NULL ) {
88
+ Py_DECREF (field_names );
89
+ Py_DECREF (field_docs );
90
+ return -1 ;
91
+ }
86
92
87
93
// copy generic fields (CPython mem-copies a template)
88
94
type -> tp_basicsize = sizeof (PyStructSequence ) - sizeof (PyObject * );
0 commit comments