Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6d5303

Browse files
authored
Merge pull request#6942 from ianthomas23/6940_contour_memory_leak
FIX: Fixed memory leak in contour
2 parents4f8d25d +631c936 commitf6d5303

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
staticintconverter(PyObject *obj,void *arrp)
535542
{
536543
array_view<T, ND> *arr = (array_view<T, ND> *)arrp;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp