From 1813e9f5f6b71cf6a9b5d2b348f688df247e25d0 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Tue, 14 Jul 2015 16:08:54 -0400 Subject: [PATCH] [GUI] Fix crash from user-after-free The QML engine was taking ownership of Account objects, and garbage collecting them when it was done with them, thus causing a crash when the C++ accessed them. Fix by explicitly marking Account objects as being owned by the C++ so QML doesn't garbage collect them. --- programs/light_client/ClientDataModel.cpp | 2 ++ programs/light_client/qml/AccountPicker.qml | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/programs/light_client/ClientDataModel.cpp b/programs/light_client/ClientDataModel.cpp index 3c48fee4..f76267d2 100644 --- a/programs/light_client/ClientDataModel.cpp +++ b/programs/light_client/ClientDataModel.cpp @@ -17,6 +17,7 @@ Account* ChainDataModel::getAccount(ObjectId id) if( itr == by_id_idx.end() ) { auto tmp = new Account; + QQmlEngine::setObjectOwnership(tmp, QQmlEngine::CppOwnership); tmp->id = id; --m_account_query_num; tmp->name = QString::number( --m_account_query_num); auto result = m_accounts.insert( tmp ); @@ -67,6 +68,7 @@ Account* ChainDataModel::getAccount(QString name) if( itr == by_name_idx.end() ) { auto tmp = new Account; + QQmlEngine::setObjectOwnership(tmp, QQmlEngine::CppOwnership); tmp->id = --m_account_query_num; tmp->name = name; auto result = m_accounts.insert( tmp ); diff --git a/programs/light_client/qml/AccountPicker.qml b/programs/light_client/qml/AccountPicker.qml index b148f64f..d94549ad 100644 --- a/programs/light_client/qml/AccountPicker.qml +++ b/programs/light_client/qml/AccountPicker.qml @@ -49,6 +49,24 @@ RowLayout { : account.id) }) } + + Behavior on text { + SequentialAnimation { + PropertyAnimation { + target: accountDetails + property: "opacity" + from: 1; to: 0 + duration: 100 + } + PropertyAction { target: accountDetails; property: "text" } + PropertyAnimation { + target: accountDetails + property: "opacity" + from: 0; to: 1 + duration: 100 + } + } + } } } }