Skip to content

Commit

Permalink
Merge pull request #6330 from nulano/imagingft-leak
Browse files Browse the repository at this point in the history
Fix memory leaks related to text features
  • Loading branch information
hugovk committed Oct 29, 2022
2 parents e849e93 + dacd5d6 commit 966e98f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/_imagingft.c
Expand Up @@ -303,31 +303,34 @@ text_layout_raqm(
goto failed;
}

len = PySequence_Size(seq);
len = PySequence_Fast_GET_SIZE(seq);
for (j = 0; j < len; j++) {
PyObject *item = PySequence_Fast_GET_ITEM(seq, j);
char *feature = NULL;
Py_ssize_t size = 0;
PyObject *bytes;

if (!PyUnicode_Check(item)) {
Py_DECREF(seq);
PyErr_SetString(PyExc_TypeError, "expected a string");
goto failed;
}

if (PyUnicode_Check(item)) {
bytes = PyUnicode_AsUTF8String(item);
if (bytes == NULL) {
goto failed;
}
feature = PyBytes_AS_STRING(bytes);
size = PyBytes_GET_SIZE(bytes);
bytes = PyUnicode_AsUTF8String(item);
if (bytes == NULL) {
Py_DECREF(seq);
goto failed;
}
feature = PyBytes_AS_STRING(bytes);
size = PyBytes_GET_SIZE(bytes);
if (!raqm_add_font_feature(rq, feature, size)) {
Py_DECREF(seq);
Py_DECREF(bytes);
PyErr_SetString(PyExc_ValueError, "raqm_add_font_feature() failed");
goto failed;
}
Py_DECREF(bytes);
}
Py_DECREF(seq);
}

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

0 comments on commit 966e98f

Please sign in to comment.