Commit a9b7ade5 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud

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
......@@ -470,10 +470,17 @@ private:
connection_ = std::make_unique<PeerConnection>([this] { cancel(); },
connection_->setOnStateChangedCb([this](const DRing::DataTransferId& id,
const DRing::DataTransferEventCode& code) {
parent_.stateChanged(peer_.toString(), id, code);
[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)
parent->stateChanged(peer, id, code);
for (auto& cb : listeners_) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment