diff --git a/Changelog b/Changelog index 6655362e1..8560ed0d2 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Unreleased - Christophe Dumez - v2.9.10 + - BUGFIX: Fix possible crash when showing torrent content (closes #1002586) + * Sun May 20 - Christophe Dumez - v2.9.9 - BUGFIX: More reliable RSS feed parsing (closes #1001777) - BUGFIX: Better support for cookies in RSS diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index ad77bead9..c6937d6a0 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -652,7 +652,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds(){ bool PropertiesWidget::applyPriorities() { qDebug("Saving files priorities"); - const std::vector priorities = PropListModel->model()->getFilesPriorities(h.get_torrent_info().num_files()); + const std::vector priorities = PropListModel->model()->getFilesPriorities(); // Save first/last piece first option state bool first_last_piece_first = h.first_last_piece_first(); // Prioritize the files diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index 244725b94..b6f5f443e 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -501,10 +501,8 @@ void torrentAdditionDialog::updateDiskSpaceLabels() { // Determine torrent size qulonglong torrent_size = 0; if(t->num_files() > 1) { - const unsigned int nbFiles = t->num_files(); - const std::vector priorities = PropListModel->model()->getFilesPriorities(nbFiles); - - for(unsigned int i=0; i priorities = PropListModel->model()->getFilesPriorities(); + for(unsigned int i=0; i 0) torrent_size += t->file_at(i).size; } @@ -598,7 +596,7 @@ bool torrentAdditionDialog::allFiltered() const { void torrentAdditionDialog::savePiecesPriorities(){ qDebug("Saving pieces priorities"); Q_ASSERT(!is_magnet); - const std::vector priorities = PropListModel->model()->getFilesPriorities(t->num_files()); + const std::vector priorities = PropListModel->model()->getFilesPriorities(); TorrentTempData::setFilesPriority(hash, priorities); } diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index a2e12166f..ba23b44c5 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -338,11 +338,10 @@ class TorrentFilesModel: public QAbstractItemModel { private: TorrentFileItem *rootItem; - TorrentFileItem **files_index; + std::vector files_index; public: TorrentFilesModel(QObject *parent=0): QAbstractItemModel(parent) { - files_index = 0; QList rootData; rootData << tr("Name") << tr("Size") << tr("Progress") << tr("Priority"); rootItem = new TorrentFileItem(rootData); @@ -350,13 +349,16 @@ public: ~TorrentFilesModel() { qDebug() << Q_FUNC_INFO << "ENTER"; - delete [] files_index; delete rootItem; qDebug() << Q_FUNC_INFO << "EXIT"; } - void updateFilesProgress(std::vector fp) { + void updateFilesProgress(const std::vector& fp) { emit layoutAboutToBeChanged(); + + if (fp.size() != files_index.size()) + return; + for(unsigned int i=0; i= 0); files_index[i]->setProgress(fp[i]); @@ -366,6 +368,10 @@ public: void updateFilesPriorities(const std::vector &fprio) { emit layoutAboutToBeChanged(); + + if (fprio.size() != files_index.size()) + return; + for(unsigned int i=0; isetPriority(fprio[i]); @@ -373,9 +379,9 @@ public: emit dataChanged(index(0,0), index(rowCount(), columnCount())); } - std::vector getFilesPriorities(unsigned int nbFiles) const { + std::vector getFilesPriorities() const { std::vector prio; - for(unsigned int i=0; igetPriority()); prio.push_back(files_index[i]->getPriority()); } @@ -541,10 +547,7 @@ public: void clear() { qDebug("clear called"); beginResetModel(); - if(files_index) { - delete [] files_index; - files_index = 0; - } + files_index.clear(); rootItem->deleteAllChildren(); endResetModel(); } @@ -555,7 +558,7 @@ public: emit layoutAboutToBeChanged(); // Initialize files_index array qDebug("Torrent contains %d files", t.num_files()); - files_index = new TorrentFileItem*[t.num_files()]; + files_index.reserve(t.num_files()); TorrentFileItem *parent = this->rootItem; TorrentFileItem *root_folder = parent; @@ -582,8 +585,7 @@ public: current_parent = new_parent; } // Actually create the file - TorrentFileItem *f = new TorrentFileItem(t, fentry, current_parent, i); - files_index[i] = f; + files_index.push_back(new TorrentFileItem(t, fentry, current_parent, i)); } emit layoutChanged(); }