Skip to content

Fixed memory leak in contour #6942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/_contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void QuadContourGenerator::append_contour_line_to_vertices(
line(i, 0) = point->x;
line(i, 1) = point->y;
}
if (PyList_Append(vertices_list, line.pyobj())) {
if (PyList_Append(vertices_list, line.pyobj_steal())) {
Py_XDECREF(vertices_list);
throw "Unable to add contour line to vertices_list";
}
Expand Down Expand Up @@ -470,8 +470,8 @@ void QuadContourGenerator::append_contour_to_vertices_and_codes(
child.clear_parent(); // To indicate it can be deleted.
}

if (PyList_Append(vertices_list, vertices.pyobj()) ||
PyList_Append(codes_list, codes.pyobj())) {
if (PyList_Append(vertices_list, vertices.pyobj_steal()) ||
PyList_Append(codes_list, codes.pyobj_steal())) {
Py_XDECREF(vertices_list);
Py_XDECREF(codes_list);
contour.delete_contour_lines();
Expand Down
7 changes: 7 additions & 0 deletions src/numpy_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,19 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
return (T *)m_data;
}

// Return a new reference.
PyObject *pyobj()
{
Py_XINCREF(m_arr);
return (PyObject *)m_arr;
}

// Steal a reference.
PyObject *pyobj_steal()
{
return (PyObject *)m_arr;
}

static int converter(PyObject *obj, void *arrp)
{
array_view<T, ND> *arr = (array_view<T, ND> *)arrp;
Expand Down