diff --git a/wpinet/src/main/native/cpp/uv/Stream.cpp b/wpinet/src/main/native/cpp/uv/Stream.cpp index fdceb7b1f2..83753cb2a4 100644 --- a/wpinet/src/main/native/cpp/uv/Stream.cpp +++ b/wpinet/src/main/native/cpp/uv/Stream.cpp @@ -97,8 +97,8 @@ void Stream::Write(std::span bufs, if (status < 0) { h.ReportError(status); } + auto ptr = h.Release(); // one-shot, but finish() may Keep() h.finish(Error(status)); - h.Release(); // this is always a one-shot })) { req->Keep(); } diff --git a/wpinet/src/main/native/include/wpinet/uv/Request.h b/wpinet/src/main/native/include/wpinet/uv/Request.h index fe1f97cf3a..d16d289dce 100644 --- a/wpinet/src/main/native/include/wpinet/uv/Request.h +++ b/wpinet/src/main/native/include/wpinet/uv/Request.h @@ -9,6 +9,7 @@ #include #include +#include #include "wpinet/uv/Error.h" @@ -92,8 +93,12 @@ class Request : public std::enable_shared_from_this { * * Derived classes can override this method for different memory management * approaches (e.g. pooled storage of requests). + * + * @return Previous shared pointer */ - virtual void Release() noexcept { m_self.reset(); } + virtual std::shared_ptr Release() noexcept { + return std::move(m_self); + } /** * Error callback. By default, this is set up to report errors to the handle