Skip to content

Commit 39a3b1d

Browse files
committed
Fixed deallocating mask images
1 parent 8c1dc81 commit 39a3b1d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/PIL/ImageFont.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,17 @@ def getmask2(
562562
_string_length_check(text)
563563
if start is None:
564564
start = (0, 0)
565-
im, size, offset = self.font.render(
565+
im = None
566+
567+
def fill(mode, size):
568+
nonlocal im
569+
570+
im = Image.core.fill(mode, size)
571+
return im
572+
573+
size, offset = self.font.render(
566574
text,
567-
Image.core.fill,
575+
fill,
568576
mode,
569577
direction,
570578
features,

src/_imagingft.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ font_render(FontObject *self, PyObject *args) {
882882
if (max_image_pixels != Py_None) {
883883
if ((long long)(width > 1 ? width : 1) * (height > 1 ? height : 1) > PyLong_AsLongLong(max_image_pixels) * 2) {
884884
PyMem_Del(glyph_info);
885-
return Py_BuildValue("O(ii)(ii)", Py_None, width, height, 0, 0);
885+
return Py_BuildValue("(ii)(ii)", width, height, 0, 0);
886886
}
887887
}
888888

@@ -898,7 +898,7 @@ font_render(FontObject *self, PyObject *args) {
898898
y_offset -= stroke_width;
899899
if (count == 0 || width == 0 || height == 0) {
900900
PyMem_Del(glyph_info);
901-
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);
901+
return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
902902
}
903903

904904
if (stroke_width) {
@@ -1113,9 +1113,10 @@ font_render(FontObject *self, PyObject *args) {
11131113
if (bitmap_converted_ready) {
11141114
FT_Bitmap_Done(library, &bitmap_converted);
11151115
}
1116+
Py_DECREF(image);
11161117
FT_Stroker_Done(stroker);
11171118
PyMem_Del(glyph_info);
1118-
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);
1119+
return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
11191120

11201121
glyph_error:
11211122
if (im->destroy) {

0 commit comments

Comments
 (0)