From 389281c4f525290149e1dc35443ccff10d1a9f5b Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 24 Feb 2019 18:16:19 +0400 Subject: pica-client: bugfix, close unused c2n connections after PICA_event_loop() is finished in order to prevent invalid access to freed memory --- pica-client/skynet.cpp | 7 ++++++- pica-client/skynet.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'pica-client') diff --git a/pica-client/skynet.cpp b/pica-client/skynet.cpp index da9f558..02be732 100644 --- a/pica-client/skynet.cpp +++ b/pica-client/skynet.cpp @@ -85,7 +85,7 @@ void SkyNet::nodelink_activated(PICA_c2n *c2n) if (self_aware) { - PICA_close_c2n(c2n); + connected_nodes_to_close.append(c2n); } else { @@ -284,6 +284,11 @@ void SkyNet::timerEvent(QTimerEvent *e) ret = PICA_event_loop(nodelinks.data(), 1); + while(!connected_nodes_to_close.empty()) + { + PICA_close_c2n(connected_nodes_to_close.takeFirst()); + } + if (ret != PICA_OK) emit StatusMsg("event loop error!", true);//show some error message } diff --git a/pica-client/skynet.h b/pica-client/skynet.h index f748e95..1c0c7d9 100644 --- a/pica-client/skynet.h +++ b/pica-client/skynet.h @@ -80,6 +80,7 @@ signals: private: Nodes nodes; QList > connecting_nodes; + QList connected_nodes_to_close; bool self_aware; QString status; struct PICA_c2n *active_nodelink; -- cgit v1.2.1