Make the beginResetModel/mList.clear()/endResetModel sequence atomic

Delete raw pointer lists after items are added to the lists
This commit is contained in:
Gaelle Braud 2026-02-24 15:00:25 +01:00
parent 5e3668fdeb
commit fb9f2dd870
3 changed files with 17 additions and 5 deletions

View file

@ -51,14 +51,17 @@ void ChatMessageFileList::setSelf(QSharedPointer<ChatMessageFileList> me) {
mCoreModelConnection = SafeConnection<ChatMessageFileList, CoreModel>::create(me, CoreModel::getInstance());
mCoreModelConnection->makeConnectToCore(&ChatMessageFileList::lUpdate, [this]() {
mustBeInMainThread(log().arg(Q_FUNC_INFO));
beginResetModel();
mList.clear();
if (!mChat) {
beginResetModel();
mList.clear();
endResetModel();
return;
}
auto chatModel = mChat->getModel();
if (!chatModel) {
beginResetModel();
mList.clear();
endResetModel();
return;
}
@ -87,9 +90,12 @@ void ChatMessageFileList::setSelf(QSharedPointer<ChatMessageFileList> me) {
contents->push_back(model);
}
mCoreModelConnection->invokeToCore([this, contents] {
beginResetModel();
mList.clear();
for (auto i : *contents)
mList << i.template objectCast<QObject>();
endResetModel();
delete contents;
});
});
});

View file

@ -178,6 +178,7 @@ void EventLogList::displayMore() {
}
add(*events);
}
delete events;
});
});
};
@ -220,6 +221,7 @@ void EventLogList::loadMessagesUpTo(std::shared_ptr<linphone::EventLog> event) {
connectItem(e);
}
add(*events);
delete events;
emit messagesLoadedUpTo(event);
});
}

View file

@ -71,12 +71,11 @@ void ConferenceInfoList::setSelf(QSharedPointer<ConferenceInfoList> me) {
setIsUpdating(true);
mCoreModelConnection->invokeToModel([this]() {
mustBeInLinphoneThread(getClassName());
beginResetModel();
mList.clear();
QList<QSharedPointer<ConferenceInfoCore>> *items = new QList<QSharedPointer<ConferenceInfoCore>>();
auto defaultAccount = CoreModel::getInstance()->getCore()->getDefaultAccount();
setAccountConnected(defaultAccount && defaultAccount->getState() == linphone::RegistrationState::Ok);
if (!defaultAccount || !mAccountConnected) {
beginResetModel();
mList.clear();
endResetModel();
setIsUpdating(false);
return;
@ -84,10 +83,13 @@ void ConferenceInfoList::setSelf(QSharedPointer<ConferenceInfoList> me) {
std::list<std::shared_ptr<linphone::ConferenceInfo>> conferenceInfos =
defaultAccount->getConferenceInformationList();
if (conferenceInfos.empty()) {
beginResetModel();
mList.clear();
endResetModel();
setIsUpdating(false);
return;
}
QList<QSharedPointer<ConferenceInfoCore>> *items = new QList<QSharedPointer<ConferenceInfoCore>>();
items->push_back(nullptr); // Add Dummy conference for today
for (auto conferenceInfo : conferenceInfos) {
// if (conferenceInfo->getState() == linphone::ConferenceInfo::State::Cancelled) {
@ -102,6 +104,8 @@ void ConferenceInfoList::setSelf(QSharedPointer<ConferenceInfoList> me) {
}
mCoreModelConnection->invokeToCore([this, items]() {
mustBeInMainThread(getClassName());
beginResetModel();
mList.clear();
for (auto &item : *items) {
connectItem(item);
mList << item.template objectCast<QObject>();