Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 936215a

Browse files
committed
Fix reference leak in draw_text_image.
svn path=/trunk/matplotlib/; revision=4620
1 parent 023414f commit 936215a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/_backend_agg.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,8 +2140,8 @@ RendererAgg::draw_text_image(const Py::Tuple& args) {
21402140
const unsigned char* buffer = NULL;
21412141
int width, height;
21422142
Py::Object image_obj = args[0];
2143+
PyArrayObject* image_array = NULL;
21432144
if (PyArray_Check(image_obj.ptr())) {
2144-
PyArrayObject* image_array = NULL;
21452145
image_array = (PyArrayObject*)PyArray_FromObject(image_obj.ptr(), PyArray_UBYTE, 2, 2);
21462146
if (!image_array)
21472147
throw Py::ValueError("First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
@@ -2164,6 +2164,8 @@ RendererAgg::draw_text_image(const Py::Tuple& args) {
21642164
}
21652165
catch (Py::TypeError) {
21662166
//x,y out of range; todo issue warning?
2167+
if (image_array)
2168+
Py_XDECREF(image_array);
21672169
return Py::Object();
21682170
}
21692171

@@ -2209,6 +2211,8 @@ RendererAgg::draw_text_image(const Py::Tuple& args) {
22092211
theRasterizer->add_path(rect2);
22102212
agg::render_scanlines(*theRasterizer, *slineP8, ri);
22112213

2214+
if (image_array)
2215+
Py_XDECREF(image_array);
22122216

22132217
return Py::Object();
22142218
}

0 commit comments

Comments
 (0)