diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-08-16 05:08:36 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2011-08-16 05:08:36 +0000 |
| commit | dac56109f3f34616ce6fdacf456ec9763d871322 (patch) | |
| tree | 7c7b6262ddd622f203727caa7505313bd9f42e66 /src/ui | |
| parent | Add user preference for rendering cache size (diff) | |
| download | inkscape-dac56109f3f34616ce6fdacf456ec9763d871322.tar.gz inkscape-dac56109f3f34616ce6fdacf456ec9763d871322.zip | |
Fix large memory leaks in the swatches panel
(bzr r10347.1.35)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/dialog/color-item.cpp | 18 | ||||
| -rw-r--r-- | src/ui/dialog/color-item.h | 3 | ||||
| -rw-r--r-- | src/ui/dialog/swatches.cpp | 24 |
3 files changed, 20 insertions, 25 deletions
diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp index 598827da9..b61925855 100644 --- a/src/ui/dialog/color-item.cpp +++ b/src/ui/dialog/color-item.cpp @@ -460,8 +460,8 @@ void ColorItem::_updatePreviews() for ( std::vector<SwatchPage*>::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) { SwatchPage* curr = *it2; index = 0; - for ( std::vector<ColorItem*>::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) { - if ( this == *zz ) { + for ( boost::ptr_vector<ColorItem>::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) { + if ( this == &*zz ) { found = true; paletteName = curr->_name; break; @@ -734,12 +734,12 @@ void ColorItem::_wireMagicColors( SwatchPage *colorSet ) { if ( colorSet ) { - for ( std::vector<ColorItem*>::iterator it = colorSet->_colors.begin(); it != colorSet->_colors.end(); ++it ) + for ( boost::ptr_vector<ColorItem>::iterator it = colorSet->_colors.begin(); it != colorSet->_colors.end(); ++it ) { - std::string::size_type pos = (*it)->def.descr.find("*{"); + std::string::size_type pos = it->def.descr.find("*{"); if ( pos != std::string::npos ) { - std::string subby = (*it)->def.descr.substr( pos + 2 ); + std::string subby = it->def.descr.substr( pos + 2 ); std::string::size_type endPos = subby.find("}*"); if ( endPos != std::string::npos ) { @@ -749,12 +749,12 @@ void ColorItem::_wireMagicColors( SwatchPage *colorSet ) if ( subby.find('E') != std::string::npos ) { - (*it)->def.setEditable( true ); + it->def.setEditable( true ); } if ( subby.find('L') != std::string::npos ) { - (*it)->_isLive = true; + it->_isLive = true; } std::string part; @@ -764,7 +764,7 @@ void ColorItem::_wireMagicColors( SwatchPage *colorSet ) if ( popVal( colorIndex, part ) ) { guint64 percent = 0; if ( popVal( percent, part ) ) { - (*it)->_linkTint( *(colorSet->_colors[colorIndex]), percent ); + it->_linkTint( colorSet->_colors[colorIndex], percent ); } } } @@ -779,7 +779,7 @@ void ColorItem::_wireMagicColors( SwatchPage *colorSet ) if ( !popVal( grayLevel, part ) ) { grayLevel = 0; } - (*it)->_linkTone( *(colorSet->_colors[colorIndex]), percent, grayLevel ); + it->_linkTone( colorSet->_colors[colorIndex], percent, grayLevel ); } } } diff --git a/src/ui/dialog/color-item.h b/src/ui/dialog/color-item.h index 9080498eb..d06082f2e 100644 --- a/src/ui/dialog/color-item.h +++ b/src/ui/dialog/color-item.h @@ -12,6 +12,7 @@ #ifndef SEEN_DIALOGS_COLOR_ITEM_H #define SEEN_DIALOGS_COLOR_ITEM_H +#include <boost/ptr_container/ptr_vector.hpp> #include <gtkmm/tooltips.h> #include "widgets/ege-paint-def.h" @@ -33,7 +34,7 @@ public: Glib::ustring _name; int _prefWidth; - std::vector<ColorItem*> _colors; + boost::ptr_vector<ColorItem> _colors; }; diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index ad3b79630..910d63873 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -885,7 +885,7 @@ void SwatchesPanel::_setDocument( SPDocument *document ) } static void recalcSwatchContents(SPDocument* doc, - std::vector<ColorItem*> &tmpColors, + boost::ptr_vector<ColorItem> &tmpColors, std::map<ColorItem*, cairo_pattern_t*> &previewMappings, std::map<ColorItem*, SPGradient*> &gradMappings) { @@ -938,7 +938,7 @@ void SwatchesPanel::handleGradientsChange(SPDocument *document) { SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0; if (docPalette) { - std::vector<ColorItem*> tmpColors; + boost::ptr_vector<ColorItem> tmpColors; std::map<ColorItem*, cairo_pattern_t*> tmpPrevs; std::map<ColorItem*, SPGradient*> tmpGrads; recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads); @@ -953,9 +953,6 @@ void SwatchesPanel::handleGradientsChange(SPDocument *document) } docPalette->_colors.swap(tmpColors); - for (std::vector<ColorItem*>::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) { - delete *it; - } // Figure out which SwatchesPanel instances are affected and update them. @@ -976,7 +973,7 @@ void SwatchesPanel::handleDefsModified(SPDocument *document) { SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0; if (docPalette && !DocTrack::queueUpdateIfNeeded(document) ) { - std::vector<ColorItem*> tmpColors; + boost::ptr_vector<ColorItem> tmpColors; std::map<ColorItem*, cairo_pattern_t*> tmpPrevs; std::map<ColorItem*, SPGradient*> tmpGrads; recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads); @@ -986,8 +983,8 @@ void SwatchesPanel::handleDefsModified(SPDocument *document) } else { int cap = std::min(docPalette->_colors.size(), tmpColors.size()); for (int i = 0; i < cap; i++) { - ColorItem* newColor = tmpColors[i]; - ColorItem* oldColor = docPalette->_colors[i]; + ColorItem *newColor = &tmpColors[i]; + ColorItem *oldColor = &docPalette->_colors[i]; if ( (newColor->def.getType() != oldColor->def.getType()) || (newColor->def.getR() != oldColor->def.getR()) || (newColor->def.getG() != oldColor->def.getG()) || @@ -1006,9 +1003,6 @@ void SwatchesPanel::handleDefsModified(SPDocument *document) for (std::map<ColorItem*, cairo_pattern_t*>::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) { cairo_pattern_destroy(it->second); } - for (std::vector<ColorItem*>::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) { - delete *it; - } } } @@ -1098,8 +1092,8 @@ void SwatchesPanel::_updateFromSelection() } sp_style_unref(tmpStyle); - for ( std::vector<ColorItem*>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) { - ColorItem* item = *it; + for ( boost::ptr_vector<ColorItem>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) { + ColorItem* item = &*it; bool isFill = (fillId == item->def.descr); bool isStroke = (strokeId == item->def.descr); item->setState( isFill, isStroke ); @@ -1140,8 +1134,8 @@ void SwatchesPanel::_rebuild() _holder->freezeUpdates(); // TODO restore once 'clear' works _holder->addPreview(_clear); _holder->addPreview(_remove); - for ( std::vector<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) { - _holder->addPreview(*it); + for ( boost::ptr_vector<ColorItem>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) { + _holder->addPreview(&*it); } _holder->thawUpdates(); } |
