Skip to content

Commit 966e98f

Browse files
authored
Merge pull request #6330 from nulano/imagingft-leak
Fix memory leaks related to text features
2 parents e849e93 + dacd5d6 commit 966e98f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/_imagingft.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,31 +303,34 @@ text_layout_raqm(
303303
goto failed;
304304
}
305305

306-
len = PySequence_Size(seq);
306+
len = PySequence_Fast_GET_SIZE(seq);
307307
for (j = 0; j < len; j++) {
308308
PyObject *item = PySequence_Fast_GET_ITEM(seq, j);
309309
char *feature = NULL;
310310
Py_ssize_t size = 0;
311311
PyObject *bytes;
312312

313313
if (!PyUnicode_Check(item)) {
314+
Py_DECREF(seq);
314315
PyErr_SetString(PyExc_TypeError, "expected a string");
315316
goto failed;
316317
}
317-
318-
if (PyUnicode_Check(item)) {
319-
bytes = PyUnicode_AsUTF8String(item);
320-
if (bytes == NULL) {
321-
goto failed;
322-
}
323-
feature = PyBytes_AS_STRING(bytes);
324-
size = PyBytes_GET_SIZE(bytes);
318+
bytes = PyUnicode_AsUTF8String(item);
319+
if (bytes == NULL) {
320+
Py_DECREF(seq);
321+
goto failed;
325322
}
323+
feature = PyBytes_AS_STRING(bytes);
324+
size = PyBytes_GET_SIZE(bytes);
326325
if (!raqm_add_font_feature(rq, feature, size)) {
326+
Py_DECREF(seq);
327+
Py_DECREF(bytes);
327328
PyErr_SetString(PyExc_ValueError, "raqm_add_font_feature() failed");
328329
goto failed;
329330
}
331+
Py_DECREF(bytes);
330332
}
333+
Py_DECREF(seq);
331334
}
332335

333336
if (!raqm_set_freetype_face(rq, self->face)) {

0 commit comments

Comments
 (0)