@@ -1205,25 +1205,27 @@ font_getvarnames(FontObject *self) {
12051205
12061206 num_namedstyles = master -> num_namedstyles ;
12071207 list_names = PyList_New (num_namedstyles );
1208+ if (list_names == NULL ) {
1209+ FT_Done_MM_Var (library , master );
1210+ return NULL ;
1211+ }
12081212
12091213 int * list_names_filled = PyMem_Malloc (num_namedstyles * sizeof (int ));
12101214 if (list_names_filled == NULL ) {
1215+ Py_DECREF (list_names );
1216+ FT_Done_MM_Var (library , master );
12111217 return PyErr_NoMemory ();
12121218 }
12131219
12141220 for (int i = 0 ; i < num_namedstyles ; i ++ ) {
12151221 list_names_filled [i ] = 0 ;
12161222 }
12171223
1218- if (list_names == NULL ) {
1219- FT_Done_MM_Var (library , master );
1220- return NULL ;
1221- }
1222-
12231224 name_count = FT_Get_Sfnt_Name_Count (self -> face );
12241225 for (i = 0 ; i < name_count ; i ++ ) {
12251226 error = FT_Get_Sfnt_Name (self -> face , i , & name );
12261227 if (error ) {
1228+ PyMem_Free (list_names_filled );
12271229 Py_DECREF (list_names );
12281230 FT_Done_MM_Var (library , master );
12291231 return geterror (error );
@@ -1236,6 +1238,12 @@ font_getvarnames(FontObject *self) {
12361238
12371239 if (master -> namedstyle [j ].strid == name .name_id ) {
12381240 list_name = Py_BuildValue ("y#" , name .string , name .string_len );
1241+ if (list_name == NULL ) {
1242+ PyMem_Free (list_names_filled );
1243+ Py_DECREF (list_names );
1244+ FT_Done_MM_Var (library , master );
1245+ return NULL ;
1246+ }
12391247 PyList_SetItem (list_names , j , list_name );
12401248 list_names_filled [j ] = 1 ;
12411249 break ;
@@ -1301,9 +1309,15 @@ font_getvaraxes(FontObject *self) {
13011309
13021310 if (name .name_id == axis .strid ) {
13031311 axis_name = Py_BuildValue ("y#" , name .string , name .string_len );
1312+ if (axis_name == NULL ) {
1313+ Py_DECREF (list_axis );
1314+ Py_DECREF (list_axes );
1315+ FT_Done_MM_Var (library , master );
1316+ return NULL ;
1317+ }
13041318 PyDict_SetItemString (
13051319 list_axis , "name" , axis_name ? axis_name : Py_None );
1306- Py_XDECREF (axis_name );
1320+ Py_DECREF (axis_name );
13071321 break ;
13081322 }
13091323 }
@@ -1357,18 +1371,25 @@ font_setvaraxes(FontObject *self, PyObject *args) {
13571371 return PyErr_NoMemory ();
13581372 }
13591373 for (i = 0 ; i < num_coords ; i ++ ) {
1360- item = PyList_GET_ITEM (axes , i );
1374+ item = PyList_GetItemRef (axes , i );
1375+ if (item == NULL ) {
1376+ free (coords );
1377+ return NULL ;
1378+ }
1379+
13611380 if (PyFloat_Check (item )) {
13621381 coord = PyFloat_AS_DOUBLE (item );
13631382 } else if (PyLong_Check (item )) {
13641383 coord = (float )PyLong_AS_LONG (item );
13651384 } else if (PyNumber_Check (item )) {
13661385 coord = PyFloat_AsDouble (item );
13671386 } else {
1387+ Py_DECREF (item );
13681388 free (coords );
13691389 PyErr_SetString (PyExc_TypeError , "list must contain numbers" );
13701390 return NULL ;
13711391 }
1392+ Py_DECREF (item );
13721393 coords [i ] = coord * 65536 ;
13731394 }
13741395
0 commit comments