From 48d2007f81d33a734f8a67bcd47a014d9f3c2cf6 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 16 May 2010 11:10:13 +0000 Subject: [PATCH] MessengerWindow::insertPeers: - memory leak - return of takeTopLevelItem and takeChild are not deleted - possible crash, when child has disappeared fixed load and save of window state, i forgot to give the name of the window to the settings class git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2916 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MessengerWindow.cpp | 22 +++++++++++++--------- retroshare-gui/src/gui/common/rwindow.cpp | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index ffef4dabe..e796c4947 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -308,7 +308,7 @@ void MessengerWindow::insertPeers() } } if (!found) { - peertreeWidget->takeTopLevelItem(index); + delete (peertreeWidget->takeTopLevelItem(index)); } else { index++; } @@ -335,7 +335,7 @@ void MessengerWindow::insertPeers() if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) && detail.gpg_id != rsPeers->getGPGOwnId()) { //don't accept anymore connection, remove from the view - peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)); + delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item))); continue; } @@ -352,7 +352,7 @@ void MessengerWindow::insertPeers() while (childIndex < gpg_item->childCount()) { std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString(); if (!rsPeers->isFriend(ssl_id)) { - gpg_item->takeChild(childIndex); + delete (gpg_item->takeChild(childIndex)); } else { childIndex++; } @@ -364,7 +364,7 @@ void MessengerWindow::insertPeers() std::list sslContacts; rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslContacts); for(std::list::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) { - QTreeWidgetItem *sslItem; + QTreeWidgetItem *sslItem = NULL; //find the corresponding sslItem child item of the gpg item bool newChild = true; @@ -375,15 +375,19 @@ void MessengerWindow::insertPeers() break; } } - if (newChild) { - sslItem = new QTreeWidgetItem(1); //set type to 1 for custom popup menu - } RsPeerDetails sslDetail; if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) { std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl; - //child has disappeared, remove it from the gpg_item - gpg_item->removeChild(sslItem); + if (sslItem) { + //child has disappeared, remove it from the gpg_item + gpg_item->removeChild(sslItem); + } + continue; + } + + if (sslItem == NULL) { + sslItem = new QTreeWidgetItem(1); //set type to 1 for custom popup menu } /* not displayed, used to find back the item */ diff --git a/retroshare-gui/src/gui/common/rwindow.cpp b/retroshare-gui/src/gui/common/rwindow.cpp index a64e98738..ae846fa0d 100644 --- a/retroshare-gui/src/gui/common/rwindow.cpp +++ b/retroshare-gui/src/gui/common/rwindow.cpp @@ -97,7 +97,7 @@ RWindow::restoreWindowState() QVariant RWindow::getSetting(QString setting, QVariant defaultValue) { - RshareSettings settings; + RshareSettings settings(_name.toStdString()); return settings.value(setting, defaultValue); } @@ -105,7 +105,7 @@ RWindow::getSetting(QString setting, QVariant defaultValue) void RWindow::saveSetting(QString prop, QVariant value) { - RshareSettings settings; + RshareSettings settings(_name.toStdString()); settings.setValue(prop, value); }