Merge pull request #459 from jpharvey/getfont_leak

stop leaking filename parameter passed to getfont
This commit is contained in:
Alex Clark ☺ 2013-12-31 02:06:05 -08:00
commit 2fc4a7441f

View File

@ -113,12 +113,6 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
"filename", "size", "index", "encoding", "font_bytes", NULL "filename", "size", "index", "encoding", "font_bytes", NULL
}; };
if (!PyArg_ParseTupleAndKeywords(args, kw, "eti|iss#", kwlist,
Py_FileSystemDefaultEncoding, &filename,
&size, &index, &encoding, &font_bytes,
&font_bytes_size))
return NULL;
if (!library) { if (!library) {
PyErr_SetString( PyErr_SetString(
PyExc_IOError, PyExc_IOError,
@ -126,10 +120,18 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
); );
return NULL; return NULL;
} }
if (!PyArg_ParseTupleAndKeywords(args, kw, "eti|iss#", kwlist,
Py_FileSystemDefaultEncoding, &filename,
&size, &index, &encoding, &font_bytes,
&font_bytes_size))
return NULL;
self = PyObject_New(FontObject, &Font_Type); self = PyObject_New(FontObject, &Font_Type);
if (!self) if (!self) {
if (filename)
PyMem_Free(filename);
return NULL; return NULL;
}
if (filename && font_bytes_size <= 0) { if (filename && font_bytes_size <= 0) {
error = FT_New_Face(library, filename, index, &self->face); error = FT_New_Face(library, filename, index, &self->face);
@ -146,6 +148,8 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
); );
error = FT_Select_Charmap(self->face, encoding_tag); error = FT_Select_Charmap(self->face, encoding_tag);
} }
if (filename)
PyMem_Free(filename);
if (error) { if (error) {
PyObject_Del(self); PyObject_Del(self);