fixup! fix: dangling reference crash in FreeSpaceLabel (#1604)

This commit is contained in:
Charles Kerr 2021-05-22 10:53:52 -05:00
parent 5c8f7d410c
commit 16ec15d84b
1 changed files with 14 additions and 22 deletions

View File

@ -73,37 +73,29 @@ void FreeSpaceLabel::onTimer()
auto* q = new RpcQueue(this);
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, alive](RpcResponse const& r)
q->add([this](RpcResponse const& r)
{
if (*alive)
// update the label
auto const bytes = dictFind<int64_t>(r.args.get(), TR_KEY_size_bytes);
if (bytes && *bytes > 1)
{
// update the label
auto const bytes = dictFind<int64_t>(r.args.get(), TR_KEY_size_bytes);
if (bytes && *bytes > 1)
{
setText(tr("%1 free").arg(Formatter::get().sizeToString(*bytes)));
}
else
{
clear();
}
// update the tooltip
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path);
setToolTip(QDir::toNativeSeparators(path ? *path : QString()));
timer_.start();
setText(tr("%1 free").arg(Formatter::get().sizeToString(*bytes)));
}
else
{
setText(QString());
}
delete alive;
// update the tooltip
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path);
setToolTip(QDir::toNativeSeparators(path ? *path : QString()));
timer_.start();
});
q->run();