Skip to content

Fix memory leak in FT2Font. #3256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _test_savefig_to_stringio(format='ps'):
values = [re.sub(b'%%.*?\n', b'', x) for x in values]

assert values[0] == values[1]
assert values[1] == values[2]
assert values[1] == values[2].replace(b'\r\n', b'\n')


@cleanup
Expand Down
24 changes: 9 additions & 15 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ RendererAgg::_draw_path_collection_generic

if ((Nfacecolors == 0 && Nedgecolors == 0) || Npaths == 0)
{
Py_XDECREF(transforms_arr);
return Py::Object();
}

Expand Down Expand Up @@ -1708,6 +1709,8 @@ RendererAgg::_draw_path_collection_generic
}
}

Py_XDECREF(transforms_arr);

return Py::Object();
}

Expand Down Expand Up @@ -2383,11 +2386,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)

int newwidth = 0;
int newheight = 0;
#if PY3K
Py::Bytes data;
#else
Py::String data;
#endif
PyObject *data;

if (xmin < xmax && ymin < ymax)
{
Expand All @@ -2406,18 +2405,12 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
// the _AsString() API.
unsigned int* dst;

#if PY3K
data = Py::Bytes(static_cast<const char*>(NULL), (int) newsize);
dst = reinterpret_cast<unsigned int*>(PyBytes_AsString(data.ptr()));
#else
data = Py::String(static_cast<const char*>(NULL), (int) newsize);
dst = reinterpret_cast<unsigned int*>(PyString_AsString(data.ptr()));
#endif

if (dst == NULL)
data = PyBytes_FromStringAndSize(NULL, newsize);
if (data == NULL)
{
throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory");
}
dst = (unsigned int *)PyBytes_AsString(data);

unsigned int* src = (unsigned int*)pixBuffer;
for (int y = ymin; y < ymax; ++y)
Expand All @@ -2436,7 +2429,8 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
bounds[3] = Py::Int(newheight);

Py::Tuple result(2);
result[0] = data;
result[0] = Py::Object(data, false);
Py_DECREF(data);
result[1] = bounds;

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ _image_module::frombuffer(const Py::Tuple& args)

args.verify_length(4);

PyObject *bufin = new_reference_to(args[0]);
PyObject *bufin = args[0].ptr();
size_t x = (long)Py::Int(args[1]);
size_t y = (long)Py::Int(args[2]);

Expand Down
4 changes: 4 additions & 0 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,10 @@ FT2Font::~FT2Font()
{
FT_Done_Glyph(glyphs[i]);
}

if (stream.descriptor.pointer != NULL) {
PyMem_Free(stream.descriptor.pointer);
}
}

int
Expand Down