From 5ebc19ced83d9718b8a88541d5a97fc81a0d1cda Mon Sep 17 00:00:00 2001 From: Ola <114643959+030611@users.noreply.github.com> Date: Tue, 11 Aug 2026 10:52:03 +0800 Subject: [PATCH] fix(python): release userdata on prepare failure --- src/lib/py/usrbio_binding.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lib/py/usrbio_binding.cc b/src/lib/py/usrbio_binding.cc index 9f46c39a..6d1988f4 100644 --- a/src/lib/py/usrbio_binding.cc +++ b/src/lib/py/usrbio_binding.cc @@ -288,17 +288,20 @@ PYBIND11_MODULE(hf3fs_py_usrbio, m) { // iov->size); userdata.inc_ref(); - py::gil_scoped_release gr; - - auto res = hf3fs_prep_io(self.get(), - (iov->base_iov ? iov->base_iov : iov).get(), - read, - iov->base, - fd, - off, - iov->size, - (void *)userdata.ptr()); + int res; + { + py::gil_scoped_release gr; + res = hf3fs_prep_io(self.get(), + (iov->base_iov ? iov->base_iov : iov).get(), + read, + iov->base, + fd, + off, + iov->size, + (void *)userdata.ptr()); + } if (res < 0) { + userdata.dec_ref(); throw OSException{-res}; }