@@ -1557,6 +1557,7 @@ RendererAgg::_draw_path_collection_generic
15571557
15581558 if ((Nfacecolors == 0 && Nedgecolors == 0 ) || Npaths == 0 )
15591559 {
1560+ Py_XDECREF (transforms_arr);
15601561 return Py::Object ();
15611562 }
15621563
@@ -1708,6 +1709,8 @@ RendererAgg::_draw_path_collection_generic
17081709 }
17091710 }
17101711
1712+ Py_XDECREF (transforms_arr);
1713+
17111714 return Py::Object ();
17121715}
17131716
@@ -2383,11 +2386,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
23832386
23842387 int newwidth = 0 ;
23852388 int newheight = 0 ;
2386- #if PY3K
2387- Py::Bytes data;
2388- #else
2389- Py::String data;
2390- #endif
2389+ PyObject *data;
23912390
23922391 if (xmin < xmax && ymin < ymax)
23932392 {
@@ -2406,18 +2405,12 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
24062405 // the _AsString() API.
24072406 unsigned int * dst;
24082407
2409- #if PY3K
2410- data = Py::Bytes (static_cast <const char *>(NULL ), (int ) newsize);
2411- dst = reinterpret_cast <unsigned int *>(PyBytes_AsString (data.ptr ()));
2412- #else
2413- data = Py::String (static_cast <const char *>(NULL ), (int ) newsize);
2414- dst = reinterpret_cast <unsigned int *>(PyString_AsString (data.ptr ()));
2415- #endif
2416-
2417- if (dst == NULL )
2408+ data = PyBytes_FromStringAndSize (NULL , newsize);
2409+ if (data == NULL )
24182410 {
24192411 throw Py::MemoryError (" RendererAgg::tostring_minimized could not allocate memory" );
24202412 }
2413+ dst = (unsigned int *)PyBytes_AsString (data);
24212414
24222415 unsigned int * src = (unsigned int *)pixBuffer;
24232416 for (int y = ymin; y < ymax; ++y)
@@ -2436,7 +2429,8 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
24362429 bounds[3 ] = Py::Int (newheight);
24372430
24382431 Py::Tuple result (2 );
2439- result[0 ] = data;
2432+ result[0 ] = Py::Object (data, false );
2433+ Py_DECREF (data);
24402434 result[1 ] = bounds;
24412435
24422436 return result;
0 commit comments