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

Skip to content

Commit 1137214

Browse files
committed
Fix memory leak in Gtk backend.
svn path=/trunk/matplotlib/; revision=4984
1 parent e117196 commit 1137214

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/_path.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,10 @@ void _add_polygon(Py::List& polygons, const std::vector<double>& polygon) {
10991099
polygon_array = (PyArrayObject*)PyArray_SimpleNew
11001100
(2, polygon_dims, PyArray_DOUBLE);
11011101
if (!polygon_array)
1102-
{
11031102
throw Py::MemoryError("Error creating polygon array");
1104-
}
11051103
double* polygon_data = (double*)PyArray_DATA(polygon_array);
11061104
memcpy(polygon_data, &polygon[0], polygon.size() * sizeof(double));
1107-
polygons.append(Py::Object((PyObject*)polygon_array));
1105+
polygons.append(Py::Object((PyObject*)polygon_array, true));
11081106
}
11091107

11101108
Py::Object _path_module::convert_path_to_polygons(const Py::Tuple& args)
@@ -1133,6 +1131,8 @@ Py::Object _path_module::convert_path_to_polygons(const Py::Tuple& args)
11331131
double x, y;
11341132
unsigned code;
11351133

1134+
polygon.reserve(path.total_vertices());
1135+
11361136
while ((code = curve.vertex(&x, &y)) != agg::path_cmd_stop)
11371137
{
11381138
if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) {

0 commit comments

Comments
 (0)