From 7947d0d7b76f690fcb1b47633f5965f2ac7a1fde Mon Sep 17 00:00:00 2001 From: cgohlke Date: Sun, 13 Jul 2014 12:50:14 -0700 Subject: [PATCH 1/4] TST: Fix test_backend_ps failures on Windows --- lib/matplotlib/tests/test_backend_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index a8133e9a4c6b..4d331ddc36c9 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -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('\r\n', '\n') @cleanup From 3f156ae2987d1ee2d471f53c07a9c659153b5799 Mon Sep 17 00:00:00 2001 From: cgohlke Date: Sun, 13 Jul 2014 13:39:32 -0700 Subject: [PATCH 2/4] TST: fix test errors on Python 3 --- lib/matplotlib/tests/test_backend_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 4d331ddc36c9..1b6aac6e37e5 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -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].replace('\r\n', '\n') + assert values[1] == values[2].replace(b'\r\n', b'\n') @cleanup From 760b2fc7ecbb158dc3d2eb51142417f04beb03e6 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 14 Jul 2014 12:18:47 -0400 Subject: [PATCH 3/4] Fix memory leak in FT2Font. --- src/ft2font.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ft2font.cpp b/src/ft2font.cpp index d54f14c5280c..58d8be8b7564 100644 --- a/src/ft2font.cpp +++ b/src/ft2font.cpp @@ -985,6 +985,10 @@ FT2Font::~FT2Font() { FT_Done_Glyph(glyphs[i]); } + + if (stream.descriptor.pointer != NULL) { + PyMem_Free(stream.descriptor.pointer); + } } int From 7b39e78b0807b8176183a5890b502f0f521b2465 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 14 Jul 2014 15:58:14 -0400 Subject: [PATCH 4/4] Fix memory leaks in the temporary rasterized images. --- src/_backend_agg.cpp | 24 +++++++++--------------- src/_image.cpp | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index c35a9da93cbb..416a3991f4ad 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -1557,6 +1557,7 @@ RendererAgg::_draw_path_collection_generic if ((Nfacecolors == 0 && Nedgecolors == 0) || Npaths == 0) { + Py_XDECREF(transforms_arr); return Py::Object(); } @@ -1708,6 +1709,8 @@ RendererAgg::_draw_path_collection_generic } } + Py_XDECREF(transforms_arr); + return Py::Object(); } @@ -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) { @@ -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(NULL), (int) newsize); - dst = reinterpret_cast(PyBytes_AsString(data.ptr())); - #else - data = Py::String(static_cast(NULL), (int) newsize); - dst = reinterpret_cast(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) @@ -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; diff --git a/src/_image.cpp b/src/_image.cpp index b1c59e9674ba..73f2624c772c 100644 --- a/src/_image.cpp +++ b/src/_image.cpp @@ -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]);