Destroy image on error

This commit is contained in:
Andrew Murray 2023-06-15 12:52:57 +10:00
parent 618c00c4ea
commit 98cc2e63ac

View File

@ -904,7 +904,8 @@ font_render(FontObject *self, PyObject *args) {
if (stroke_width) { if (stroke_width) {
error = FT_Stroker_New(library, &stroker); error = FT_Stroker_New(library, &stroker);
if (error) { if (error) {
return geterror(error); geterror(error);
goto glyph_error;
} }
FT_Stroker_Set( FT_Stroker_Set(
@ -927,7 +928,8 @@ font_render(FontObject *self, PyObject *args) {
error = error =
FT_Load_Glyph(self->face, glyph_info[i].index, load_flags | FT_LOAD_RENDER); FT_Load_Glyph(self->face, glyph_info[i].index, load_flags | FT_LOAD_RENDER);
if (error) { if (error) {
return geterror(error); geterror(error);
goto glyph_error;
} }
glyph_slot = self->face->glyph; glyph_slot = self->face->glyph;
@ -958,7 +960,8 @@ font_render(FontObject *self, PyObject *args) {
error = FT_Load_Glyph(self->face, glyph_info[i].index, load_flags); error = FT_Load_Glyph(self->face, glyph_info[i].index, load_flags);
if (error) { if (error) {
return geterror(error); geterror(error);
goto glyph_error;
} }
glyph_slot = self->face->glyph; glyph_slot = self->face->glyph;
@ -972,7 +975,8 @@ font_render(FontObject *self, PyObject *args) {
error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, &origin, 1); error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, &origin, 1);
} }
if (error) { if (error) {
return geterror(error); geterror(error);
goto glyph_error;
} }
bitmap_glyph = (FT_BitmapGlyph)glyph; bitmap_glyph = (FT_BitmapGlyph)glyph;
@ -1114,6 +1118,12 @@ font_render(FontObject *self, PyObject *args) {
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset); return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);
glyph_error: glyph_error:
if (im->destroy) {
im->destroy(im);
}
if (im->image) {
free(im->image);
}
if (stroker != NULL) { if (stroker != NULL) {
FT_Done_Glyph(glyph); FT_Done_Glyph(glyph);
} }