diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 416a3991f4ad..b088c97c9aa3 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); @@ -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_rgba_minimized could not allocate memory"); + } } Py::Tuple bounds(4); @@ -2429,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;