Skip to content
Snippets Groups Projects
Commit a9b7ade5 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

p2p: fix heap-use-after-free error

Because the callback is shared by multiple objects, parent MUST be passed
as a weak pointer to avoid any use after free.

Change-Id: Ia03b1aa7326922fe3d07a62f0ac73e9a15da40b0
Gitlab: #307
parent d76904f6
No related branches found
Tags 1.1.0
No related merge requests found
......@@ -470,10 +470,17 @@ private:
connection_ = std::make_unique<PeerConnection>([this] { cancel(); },
peer_.toString(),
std::move(tls_ep_));
connection_->setOnStateChangedCb([this](const DRing::DataTransferId& id,
const DRing::DataTransferEventCode& code) {
parent_.stateChanged(peer_.toString(), id, code);
});
connection_->setOnStateChangedCb(
[p = parent_.weak(),
peer = peer_.toString()](const DRing::DataTransferId& id,
const DRing::DataTransferEventCode& code) {
// NOTE: this callback is shared by all potential inputs/output, not
// only used by connection_, weak pointers MUST be used.
auto parent = p.lock();
if (!parent)
return;
parent->stateChanged(peer, id, code);
});
for (auto& cb : listeners_) {
cb(connection_.get());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment