Skip to content

Commit a3ff673

Browse files
committed
Move final assignment later
1 parent 7fcf820 commit a3ff673

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/pybind11/detail/class.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
603603

604604
// Fill in all the information, and then downgrade as requested by the caller, or raise an
605605
// error if that's not possible.
606-
view->obj = obj;
607606
view->buf = info->ptr;
608607
view->itemsize = info->itemsize;
609608
view->len = view->itemsize;
@@ -659,7 +658,10 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
659658
}
660659
}
661660

661+
// Set these after all checks so they don't leak out into the caller, and can be automatically
662+
// cleaned up on error.
662663
view->internal = info.release();
664+
view->obj = obj;
663665
Py_INCREF(view->obj);
664666
return 0;
665667
}

0 commit comments

Comments
 (0)