@@ -714,22 +714,22 @@ void DynamicLibrary::RegisterCallback(const FunctionCallbackInfo<Value>& args) { |
714 | 714 | return; |
715 | 715 | } |
716 | 716 |
|
717 | | - auto callback = new FFICallback{.owner = lib, |
718 | | - .env = env, |
719 | | - .thread_id = std::this_thread::get_id(), |
720 | | - .fn = Global<Function>(isolate, fn), |
721 | | - .closure = nullptr, |
722 | | - .ptr = nullptr, |
723 | | - .cif = {}, |
724 | | - .args = std::move(callback_args), |
725 | | - .return_type = return_type}; |
| 717 | + auto callback = std::unique_ptr<FFICallback>( |
| 718 | + new FFICallback{.owner = lib, |
| 719 | + .env = env, |
| 720 | + .thread_id = std::this_thread::get_id(), |
| 721 | + .fn = Global<Function>(isolate, fn), |
| 722 | + .closure = nullptr, |
| 723 | + .ptr = nullptr, |
| 724 | + .cif = {}, |
| 725 | + .args = std::move(callback_args), |
| 726 | + .return_type = return_type}); |
726 | 727 |
|
727 | 728 | callback->closure = static_cast<ffi_closure*>( |
728 | 729 | ffi_closure_alloc(sizeof(ffi_closure), &callback->ptr)); |
729 | 730 |
|
730 | 731 | if (callback->closure == nullptr) { |
731 | 732 | THROW_ERR_FFI_CALL_FAILED(env, "ffi_closure_alloc failed"); |
732 | | - delete callback; |
733 | 733 | return; |
734 | 734 | } |
735 | 735 |
|
@@ -754,7 +754,6 @@ void DynamicLibrary::RegisterCallback(const FunctionCallbackInfo<Value>& args) { |
754 | 754 | } |
755 | 755 |
|
756 | 756 | THROW_ERR_FFI_CALL_FAILED(env, msg); |
757 | | - delete callback; |
758 | 757 | return; |
759 | 758 | } |
760 | 759 |
|
@@ -778,14 +777,12 @@ void DynamicLibrary::RegisterCallback(const FunctionCallbackInfo<Value>& args) { |
778 | 777 | } |
779 | 778 |
|
780 | 779 | THROW_ERR_FFI_CALL_FAILED(env, msg); |
781 | | - delete callback; |
782 | 780 | return; |
783 | 781 | } |
784 | 782 |
|
785 | | - lib->callbacks_.emplace(callback->ptr, callback); |
786 | | - args.GetReturnValue().Set(BigInt::NewFromUnsigned( |
787 | | - isolate, |
788 | | - static_cast<uint64_t>(reinterpret_cast<uintptr_t>(callback->ptr)))); |
| 783 | + auto ret = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(callback->ptr)); |
| 784 | + lib->callbacks_.emplace(callback->ptr, std::move(callback)); |
| 785 | + args.GetReturnValue().Set(BigInt::NewFromUnsigned(isolate, ret)); |
789 | 786 | } |
790 | 787 |
|
791 | 788 | void DynamicLibrary::UnregisterCallback( |
|