Skip to content

Commit 45243eb

Browse files
committed
Merge pull request #6942 from ianthomas23/6940_contour_memory_leak
FIX: Fixed memory leak in contour
1 parent ff40b7e commit 45243eb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/_contour.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void QuadContourGenerator::append_contour_line_to_vertices(
396396
line(i, 0) = point->x;
397397
line(i, 1) = point->y;
398398
}
399-
if (PyList_Append(vertices_list, line.pyobj())) {
399+
if (PyList_Append(vertices_list, line.pyobj_steal())) {
400400
Py_XDECREF(vertices_list);
401401
throw "Unable to add contour line to vertices_list";
402402
}
@@ -470,8 +470,8 @@ void QuadContourGenerator::append_contour_to_vertices_and_codes(
470470
child.clear_parent(); // To indicate it can be deleted.
471471
}
472472

473-
if (PyList_Append(vertices_list, vertices.pyobj()) ||
474-
PyList_Append(codes_list, codes.pyobj())) {
473+
if (PyList_Append(vertices_list, vertices.pyobj_steal()) ||
474+
PyList_Append(codes_list, codes.pyobj_steal())) {
475475
Py_XDECREF(vertices_list);
476476
Py_XDECREF(codes_list);
477477
contour.delete_contour_lines();

src/numpy_cpp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,19 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
525525
return (T *)m_data;
526526
}
527527

528+
// Return a new reference.
528529
PyObject *pyobj()
529530
{
530531
Py_XINCREF(m_arr);
531532
return (PyObject *)m_arr;
532533
}
533534

535+
// Steal a reference.
536+
PyObject *pyobj_steal()
537+
{
538+
return (PyObject *)m_arr;
539+
}
540+
534541
static int converter(PyObject *obj, void *arrp)
535542
{
536543
array_view<T, ND> *arr = (array_view<T, ND> *)arrp;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy