python: free internal string buffer if needed in set_list_of_strings (#44287)

This commit is contained in:
Benjamin Dauvergne 2020-06-20 08:12:05 +02:00
parent f80b2bb50e
commit 8591451270
1 changed files with 5 additions and 1 deletions

View File

@ -332,13 +332,17 @@ set_list_of_strings(GList **a_list, PyObject *seq) {
l = PySequence_Length(seq);
}
for (i=0; i<l; i++) {
const char *astr = NULL;
PyObject *pystr = PySequence_Fast_GET_ITEM(seq, i);
if (! PyString_Check(pystr)) {
PyErr_SetString(PyExc_TypeError,
"value should be a tuple of strings");
goto failure;
}
list = g_list_append(list, g_strdup(PyString_AsString(pystr)));
astr = PyString_AsString(pystr);
list = g_list_append(list, g_strdup(astr));
PyStringFree(astr);
}
free_list(a_list, (GFunc)g_free);
*a_list = list;