From d797bc18b4822098345d47212c4627f77173ae90 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 29 Jul 2014 12:27:07 -0400 Subject: [PATCH 1/3] Fix #3304. Fix crash in tostring_rgba_minimized when the region has zero-size. Thanks to @neothemachine for tracking this down. --- src/_backend_agg.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 416a3991f4ad..a392ce5c9f5e 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -2420,6 +2420,12 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) *dst = src[y * width + x]; } } + } else { + data = PyBytes_FromStringAndSize(NULL, 0); + if (data == NULL) + { + throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory"); + } } Py::Tuple bounds(4); From a501abb7385dd0dc7480e87b72dc540a27d7fcc2 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 29 Jul 2014 13:17:02 -0400 Subject: [PATCH 2/3] Fix exception message --- src/_backend_agg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index a392ce5c9f5e..a141b6ab4a73 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -2408,7 +2408,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) data = PyBytes_FromStringAndSize(NULL, newsize); if (data == NULL) { - throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory"); + throw Py::MemoryError("RendererAgg::tostring_rgba_minimized could not allocate memory"); } dst = (unsigned int *)PyBytes_AsString(data); @@ -2424,7 +2424,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) data = PyBytes_FromStringAndSize(NULL, 0); if (data == NULL) { - throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory"); + throw Py::MemoryError("RendererAgg::tostring_rgba_minimized could not allocate memory"); } } From 5b0e0d86f080cd06cd4ad0fe0ca44f048abffedb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 29 Jul 2014 13:17:10 -0400 Subject: [PATCH 3/3] Simplify reference counting --- src/_backend_agg.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index a141b6ab4a73..b088c97c9aa3 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -2435,8 +2435,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) bounds[3] = Py::Int(newheight); Py::Tuple result(2); - result[0] = Py::Object(data, false); - Py_DECREF(data); + result[0] = Py::Object(data, true); result[1] = bounds; return result;