mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix a potential crash in the FreeType bindings, if the string object passed in from python is deleted before the face oject.
This commit is contained in:
parent
488b82b6ff
commit
6d355b82b8
@ -22,6 +22,7 @@ typedef struct {
|
||||
// ensure it is garbage collected before the library object, to prevent
|
||||
// segfaults.
|
||||
PyObject *library;
|
||||
PyObject *data;
|
||||
} Face;
|
||||
|
||||
typedef struct {
|
||||
@ -40,9 +41,12 @@ Face_dealloc(Face* self)
|
||||
}
|
||||
self->face = NULL;
|
||||
|
||||
Py_DECREF(self->library);
|
||||
Py_XDECREF(self->library);
|
||||
self->library = NULL;
|
||||
|
||||
Py_XDECREF(self->data);
|
||||
self->data = NULL;
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
@ -55,8 +59,6 @@ Face_init(Face *self, PyObject *args, PyObject *kwds)
|
||||
PyObject *ft;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "Os#", &ft, &data, &sz)) return -1;
|
||||
self->library = ft;
|
||||
Py_XINCREF(ft);
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
error = FT_New_Memory_Face( ( (FreeType*)ft )->library,
|
||||
@ -70,6 +72,10 @@ Face_init(Face *self, PyObject *args, PyObject *kwds)
|
||||
PyErr_Format(FreeTypeError, "Failed to initialize the Font with error: 0x%x", error);
|
||||
return -1;
|
||||
}
|
||||
self->library = ft;
|
||||
Py_XINCREF(ft);
|
||||
|
||||
self->data = PySequence_GetItem(args, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user