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
This commit is contained in:
thunder2 2010-05-16 11:10:13 +00:00
parent 93cd5e67f8
commit 48d2007f81
2 changed files with 15 additions and 11 deletions

View File

@ -308,7 +308,7 @@ void MessengerWindow::insertPeers()
} }
} }
if (!found) { if (!found) {
peertreeWidget->takeTopLevelItem(index); delete (peertreeWidget->takeTopLevelItem(index));
} else { } else {
index++; index++;
} }
@ -335,7 +335,7 @@ void MessengerWindow::insertPeers()
if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection)
&& detail.gpg_id != rsPeers->getGPGOwnId()) { && detail.gpg_id != rsPeers->getGPGOwnId()) {
//don't accept anymore connection, remove from the view //don't accept anymore connection, remove from the view
peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)); delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)));
continue; continue;
} }
@ -352,7 +352,7 @@ void MessengerWindow::insertPeers()
while (childIndex < gpg_item->childCount()) { while (childIndex < gpg_item->childCount()) {
std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString(); std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString();
if (!rsPeers->isFriend(ssl_id)) { if (!rsPeers->isFriend(ssl_id)) {
gpg_item->takeChild(childIndex); delete (gpg_item->takeChild(childIndex));
} else { } else {
childIndex++; childIndex++;
} }
@ -364,7 +364,7 @@ void MessengerWindow::insertPeers()
std::list<std::string> sslContacts; std::list<std::string> sslContacts;
rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslContacts); rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslContacts);
for(std::list<std::string>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) { for(std::list<std::string>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) {
QTreeWidgetItem *sslItem; QTreeWidgetItem *sslItem = NULL;
//find the corresponding sslItem child item of the gpg item //find the corresponding sslItem child item of the gpg item
bool newChild = true; bool newChild = true;
@ -375,15 +375,19 @@ void MessengerWindow::insertPeers()
break; break;
} }
} }
if (newChild) {
sslItem = new QTreeWidgetItem(1); //set type to 1 for custom popup menu
}
RsPeerDetails sslDetail; RsPeerDetails sslDetail;
if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) { if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) {
std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl; std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl;
//child has disappeared, remove it from the gpg_item if (sslItem) {
gpg_item->removeChild(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 */ /* not displayed, used to find back the item */

View File

@ -97,7 +97,7 @@ RWindow::restoreWindowState()
QVariant QVariant
RWindow::getSetting(QString setting, QVariant defaultValue) RWindow::getSetting(QString setting, QVariant defaultValue)
{ {
RshareSettings settings; RshareSettings settings(_name.toStdString());
return settings.value(setting, defaultValue); return settings.value(setting, defaultValue);
} }
@ -105,7 +105,7 @@ RWindow::getSetting(QString setting, QVariant defaultValue)
void void
RWindow::saveSetting(QString prop, QVariant value) RWindow::saveSetting(QString prop, QVariant value)
{ {
RshareSettings settings; RshareSettings settings(_name.toStdString());
settings.setValue(prop, value); settings.setValue(prop, value);
} }