diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 2034c39582..c9320057c9 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -878,7 +878,44 @@ NativeValue* CreateJsServiceExtensionContext(NativeEngine& engine, std::shared_p JSServiceExtensionConnection::JSServiceExtensionConnection(NativeEngine& engine) : engine_(engine) {} -JSServiceExtensionConnection::~JSServiceExtensionConnection() = default; +JSServiceExtensionConnection::~JSServiceExtensionConnection() +{ + if (jsConnectionObject_ == nullptr) { + return; + } + + uv_loop_t *loop = engine_.GetUVLoop(); + if (loop == nullptr) { + return; + } + + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + return; + } + work->data = reinterpret_cast(jsConnectionObject_.release()); + int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + if (work == nullptr) { + return; + } + if (work->data == nullptr) { + delete work; + work = nullptr; + return; + } + delete reinterpret_cast(work->data); + work->data = nullptr; + delete work; + work = nullptr; + }); + if (ret != 0) { + delete reinterpret_cast(work->data); + work->data = nullptr; + delete work; + work = nullptr; + } +} void JSServiceExtensionConnection::SetConnectionId(int64_t id) {