aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2019-12-17 14:18:54 +0000
committerxiphon <xiphon@protonmail.com>2019-12-17 14:18:54 +0000
commite0ab9aa898fdd813c73ea3c47ffb0f9b5f80e9cf (patch)
tree032a106b64c293feec2acf81c10fa1c4c6e4703a /src/model
parentc9900c05b22d8e4aa847fea4428b432d6cfa47d7 (diff)
downloadmonzero-gui-e0ab9aa898fdd813c73ea3c47ffb0f9b5f80e9cf.tar.gz
monzero-gui-e0ab9aa898fdd813c73ea3c47ffb0f9b5f80e9cf.tar.xz
monzero-gui-e0ab9aa898fdd813c73ea3c47ffb0f9b5f80e9cf.zip
SubaddressAccount: fix use-after-free bug
Diffstat (limited to 'src/model')
-rw-r--r--src/model/SubaddressAccountModel.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/model/SubaddressAccountModel.cpp b/src/model/SubaddressAccountModel.cpp
index b8258296..c84b4532 100644
--- a/src/model/SubaddressAccountModel.cpp
+++ b/src/model/SubaddressAccountModel.cpp
@@ -59,22 +59,28 @@ QVariant SubaddressAccountModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddressAccount->count())
return {};
- Monero::SubaddressAccountRow * sr = m_subaddressAccount->getRow(index.row());
+ QVariant result;
- QVariant result = "";
- switch (role) {
- case SubaddressAccountAddressRole:
- result = QString::fromStdString(sr->getAddress());
- break;
- case SubaddressAccountLabelRole:
- result = QString::fromStdString(sr->getLabel());
- break;
- case SubaddressAccountBalanceRole:
- result = QString::fromStdString(sr->getBalance());
- break;
- case SubaddressAccountUnlockedBalanceRole:
- result = QString::fromStdString(sr->getUnlockedBalance());
- break;
+ bool found = m_subaddressAccount->getRow(index.row(), [&result, &role](const Monero::SubaddressAccountRow &row) {
+ switch (role) {
+ case SubaddressAccountAddressRole:
+ result = QString::fromStdString(row.getAddress());
+ break;
+ case SubaddressAccountLabelRole:
+ result = QString::fromStdString(row.getLabel());
+ break;
+ case SubaddressAccountBalanceRole:
+ result = QString::fromStdString(row.getBalance());
+ break;
+ case SubaddressAccountUnlockedBalanceRole:
+ result = QString::fromStdString(row.getUnlockedBalance());
+ break;
+ default:
+ qCritical() << "Unimplemented role" << role;
+ }
+ });
+ if (!found) {
+ qCritical("%s: internal error: invalid index %d", __FUNCTION__, index.row());
}
return result;