Skip to content

Commit

Permalink
Merge pull request matplotlib#3324 from mdboom/backend-agg-crash
Browse files Browse the repository at this point in the history
BUG : fixes memory corruption issues with zero-size rasterized artists

Fix matplotlib#3304.
  • Loading branch information
tacaswell authored and Joel B. Mohler committed Aug 14, 2014
1 parent e1c7ed8 commit fffa465
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/_backend_agg.cpp
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit fffa465

Please sign in to comment.