mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
fix: dangling reference crash in FreeSpaceLabel (#1604)
This commit is contained in:
parent
270a937909
commit
090a4b5ff8
1 changed files with 22 additions and 14 deletions
|
@ -73,29 +73,37 @@ void FreeSpaceLabel::onTimer()
|
||||||
|
|
||||||
auto* q = new RpcQueue();
|
auto* q = new RpcQueue();
|
||||||
|
|
||||||
|
auto* alive = new bool(true);
|
||||||
|
connect(this, &QObject::destroyed, [alive] { *alive = false; });
|
||||||
|
|
||||||
q->add([this, &args]()
|
q->add([this, &args]()
|
||||||
{
|
{
|
||||||
return session_->exec("free-space", &args);
|
return session_->exec("free-space", &args);
|
||||||
});
|
});
|
||||||
|
|
||||||
q->add([this](RpcResponse const& r)
|
q->add([this, alive](RpcResponse const& r)
|
||||||
{
|
{
|
||||||
// update the label
|
if (*alive)
|
||||||
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)));
|
// update the label
|
||||||
}
|
auto const bytes = dictFind<int64_t>(r.args.get(), TR_KEY_size_bytes);
|
||||||
else
|
if (bytes && *bytes > 1)
|
||||||
{
|
{
|
||||||
setText(QString());
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the tooltip
|
delete alive;
|
||||||
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path);
|
|
||||||
setToolTip(QDir::toNativeSeparators(path ? *path : QString()));
|
|
||||||
|
|
||||||
timer_.start();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
q->run();
|
q->run();
|
||||||
|
|
Loading…
Reference in a new issue