fix: dangling reference crash in FreeSpaceLabel (#1604)

This commit is contained in:
Charles Kerr 2021-01-24 22:20:21 -06:00 committed by GitHub
parent 270a937909
commit 090a4b5ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 14 deletions

View File

@ -73,12 +73,17 @@ void FreeSpaceLabel::onTimer()
auto* q = new RpcQueue();
auto* alive = new bool(true);
connect(this, &QObject::destroyed, [alive] { *alive = false; });
q->add([this, &args]()
{
return session_->exec("free-space", &args);
});
q->add([this](RpcResponse const& r)
q->add([this, alive](RpcResponse const& r)
{
if (*alive)
{
// update the label
auto const bytes = dictFind<int64_t>(r.args.get(), TR_KEY_size_bytes);
@ -88,7 +93,7 @@ void FreeSpaceLabel::onTimer()
}
else
{
setText(QString());
clear();
}
// update the tooltip
@ -96,6 +101,9 @@ void FreeSpaceLabel::onTimer()
setToolTip(QDir::toNativeSeparators(path ? *path : QString()));
timer_.start();
}
delete alive;
});
q->run();