From ff5b8e13059de1471effb6250bac27b1666d82e7 Mon Sep 17 00:00:00 2001 From: WhiteCat6142 Date: Fri, 16 Aug 2024 16:15:25 +0900 Subject: [PATCH] fix: memory check --- src/nostr_relay_simple.hpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/nostr_relay_simple.hpp b/src/nostr_relay_simple.hpp index 120cc4f..3c835bf 100644 --- a/src/nostr_relay_simple.hpp +++ b/src/nostr_relay_simple.hpp @@ -49,24 +49,28 @@ namespace cpp_nostr return; std::string id = std::string(*(*iter).as_string()); NostrEventSubId sub_id = (NostrEventSubId)std::stoul(id); - NostrEventCallback &fn = this->list.at(sub_id); - ++iter; - NostrEvent ev = cast(*iter); - if(NostrEventYYJSON::verify_event(ev)) - fn(ev); - else - std::cout << "invalid sig" <list.find(sub_id); iter2 != std::end(this->list) ) + { + NostrEventCallback fn = iter2->second; + ++iter; + NostrEvent ev = cast(*iter); + if(NostrEventYYJSON::verify_event(ev)) + fn(ev); + else + std::cout << "invalid sig" <pub_list.size()) < *pr = this->pub_list.at(id); - pr->set_value(true); - pub_list.erase(id); - delete pr; + if ( auto iter = this->pub_list.find(id); iter != std::end(this->pub_list) ) + { + std::promise *pr = iter->second; + pr->set_value(true); + pub_list.erase(id); + delete pr; + } } }); } NostrEventSubId subscribe(NostrEventCallback callback, const NostrSubscription &sub) override @@ -90,6 +94,7 @@ namespace cpp_nostr if (!relay->send(NostrRelayUtils::makePublishCommand(ev))) { pr->set_value(false); + delete pr; return ft; } pub_list.insert_or_assign(std::string(id), pr);