diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-10-04 16:26:34 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-10-05 10:35:21 +0000 |
| commit | 95e00bdf7075329277cac97a6fd0a929c9a8e453 (patch) | |
| tree | ff4521ff8f759eec5aac329efbf00bbca68f0d70 /src | |
| parent | Fix segfault with bad SVG file. (diff) | |
| download | inkscape-95e00bdf7075329277cac97a6fd0a929c9a8e453.tar.gz inkscape-95e00bdf7075329277cac97a6fd0a929c9a8e453.zip | |
Fix some memory leaks found by scan-build
Diffstat (limited to 'src')
| -rw-r--r-- | src/ege-color-prof-tracker.cpp | 1 | ||||
| -rw-r--r-- | src/extension/internal/wmf-print.cpp | 2 | ||||
| -rw-r--r-- | src/gradient-drag.cpp | 2 | ||||
| -rw-r--r-- | src/knot-holder-entity.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-copy_rotate.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-offset.cpp | 3 | ||||
| -rw-r--r-- | src/live_effects/lpe-powerclip.cpp | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-powerstroke-interpolators.h | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/fontbutton.cpp | 2 | ||||
| -rw-r--r-- | src/object/box3d-side.cpp | 1 | ||||
| -rw-r--r-- | src/object/sp-text.cpp | 8 | ||||
| -rw-r--r-- | src/ui/dialog/paint-servers.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 1 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 4 | ||||
| -rw-r--r-- | src/ui/tools/pen-tool.cpp | 41 | ||||
| -rw-r--r-- | src/widgets/sp-xmlview-tree.cpp | 3 |
16 files changed, 41 insertions, 38 deletions
diff --git a/src/ege-color-prof-tracker.cpp b/src/ege-color-prof-tracker.cpp index 6672aef81..853cc11c8 100644 --- a/src/ege-color-prof-tracker.cpp +++ b/src/ege-color-prof-tracker.cpp @@ -496,6 +496,7 @@ void handle_property_change(GdkScreen* screen, const gchar* name) &actualType, &actualFormat, &nitems, &bytesAfter, &prop ) == Success ) { gpointer profile = g_memdup( prop, nitems ); set_profile( monitor, (const guint8*)profile, nitems ); + free(profile); XFree(prop); } else { g_warning("Problem reading profile from root window"); diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 6f3485fe5..6b8bcf242 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -1402,7 +1402,7 @@ unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *te free(unicode_text); // in some cases a UTF string may reduce to NO latin1 characters, which returns NULL - if(!latin1_text){ return 0; } + if(!latin1_text){free(adx); return 0; } //PPT gets funky with text within +-1 degree of a multiple of 90, but only for SOME fonts.Snap those to the central value //Some funky ones: Arial, Times New Roman diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 88247a21a..47b032c2a 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2915,6 +2915,8 @@ void GrDrag::deleteSelected(bool just_one) } if (!present) endstoplist.push_back(stopinfo); + else + delete stopinfo; } } break; diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 19f3b8ef1..8c1327c8b 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -387,7 +387,7 @@ void FilterKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &o SPFilter *filter = (item->style && item->style->filter.href) ? dynamic_cast<SPFilter *>(item->style->getFilter()) : nullptr; if(!filter) return; Geom::OptRect orig_bbox = item->visualBounds(); - Geom::Rect *new_bbox = _topleft ? new Geom::Rect(p,orig_bbox->max()) : new Geom::Rect(orig_bbox->min(), p); + std::unique_ptr<Geom::Rect> new_bbox(_topleft ? new Geom::Rect(p,orig_bbox->max()) : new Geom::Rect(orig_bbox->min(), p)); if(_topleft) { float x_a = filter->width.computed; float y_a = filter->height.computed; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f9c083d39..57b793993 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -531,7 +531,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) } Geom::PathVector triangle; triangle.push_back(divider); - Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(triangle, path_out); + std::unique_ptr<Geom::PathIntersectionGraph> pig(new Geom::PathIntersectionGraph(triangle, path_out)); if (pig && !path_out.empty() && !triangle.empty()) { path_out = pig->getIntersection(); } diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 401875700..72d29d0c1 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -294,7 +294,6 @@ LPEOffset::doEffect_path(Geom::PathVector const & path_in) Geom::PathVector ret; Geom::PathVector open_ret; Geom::PathVector ret_outline; - Geom::PathIntersectionGraph *pig; for (Geom::PathVector::const_iterator path_it = filled_rule_pathv.begin(); path_it != filled_rule_pathv.end(); ++path_it) { Geom::Path original = (*path_it); if (original.empty()) { @@ -430,7 +429,7 @@ LPEOffset::doEffect_path(Geom::PathVector const & path_in) if (offset < 0) { sp_flatten(ret_outline, fill_nonZero); - pig = new Geom::PathIntersectionGraph(ret, ret_outline); + std::unique_ptr<Geom::PathIntersectionGraph> pig(new Geom::PathIntersectionGraph(ret, ret_outline)); if (pig && !ret_outline.empty() && !ret.empty()) { ret = pig->getAminusB(); } diff --git a/src/live_effects/lpe-powerclip.cpp b/src/live_effects/lpe-powerclip.cpp index 461a22125..cb444149c 100644 --- a/src/live_effects/lpe-powerclip.cpp +++ b/src/live_effects/lpe-powerclip.cpp @@ -306,7 +306,7 @@ LPEPowerClip::doEffect_path(Geom::PathVector const & path_in){ if (c) { Geom::PathVector c_pv = c->get_pathvector(); c_pv *= sp_item_transform_repr (sp_lpe_item).inverse(); - Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(c_pv, path_out); + std::unique_ptr<Geom::PathIntersectionGraph> pig(new Geom::PathIntersectionGraph(c_pv, path_out)); if (pig && !c_pv.empty() && !path_in.empty()) { path_out = pig->getIntersection(); } @@ -348,7 +348,7 @@ LPEPowerClip::flattenClip(SPItem * clip_data, Geom::PathVector &path_in) if (c) { Geom::PathVector c_pv = c->get_pathvector(); c_pv *= sp_item_transform_repr (sp_lpe_item).inverse(); - Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(c_pv, path_in); + std::unique_ptr<Geom::PathIntersectionGraph> pig(new Geom::PathIntersectionGraph(c_pv, path_in)); if (pig && !c_pv.empty() && !path_in.empty()) { path_in = pig->getIntersection(); } diff --git a/src/live_effects/lpe-powerstroke-interpolators.h b/src/live_effects/lpe-powerstroke-interpolators.h index 4828a0bbb..65bee9a63 100644 --- a/src/live_effects/lpe-powerstroke-interpolators.h +++ b/src/live_effects/lpe-powerstroke-interpolators.h @@ -199,6 +199,7 @@ public: Spiro::spiro_run(controlpoints, len, fit); fit *= Scale(1,scale_y); + delete controlpoints; return fit; }; diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 07bc5d6ab..038a58fc6 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -38,7 +38,7 @@ FontButtonParam::param_set_default() void FontButtonParam::param_update_default(const gchar * default_value) { - defvalue = (Glib::ustring)strdup(default_value); + defvalue = Glib::ustring(default_value); } bool diff --git a/src/object/box3d-side.cpp b/src/object/box3d-side.cpp index 6fcf22a9c..53b37f6c8 100644 --- a/src/object/box3d-side.cpp +++ b/src/object/box3d-side.cpp @@ -183,6 +183,7 @@ void Box3DSide::set_shape() { !box3d_get_corner_screen(box, corners[3]).isFinite() ) { g_warning ("Trying to draw a 3D box side with invalid coordinates.\n"); + delete c; return; } diff --git a/src/object/sp-text.cpp b/src/object/sp-text.cpp index bf406601e..7786bf69c 100644 --- a/src/object/sp-text.cpp +++ b/src/object/sp-text.cpp @@ -767,8 +767,8 @@ unsigned SPText::_buildLayoutInput(SPObject *object, Inkscape::Text::Layout::Opt Shape* SPText::_buildExclusionShape() const { - Shape *result = new Shape(); // Union of all exclusion shapes - Shape *shape_temp = new Shape(); + std::unique_ptr<Shape> result(new Shape()); // Union of all exclusion shapes + std::unique_ptr<Shape> shape_temp(new Shape()); for(auto shape_id : style->shape_subtract.shape_ids) { @@ -799,7 +799,7 @@ Shape* SPText::_buildExclusionShape() const uncross->ConvertToShape( sh ); if (result->hasEdges()) { - shape_temp->Booleen(result, uncross, bool_op_union); + shape_temp->Booleen(result.get(), uncross, bool_op_union); std::swap(result, shape_temp); } else { result->Copy(uncross); @@ -807,7 +807,7 @@ Shape* SPText::_buildExclusionShape() const } } } - return result; + return result.release(); } diff --git a/src/ui/dialog/paint-servers.cpp b/src/ui/dialog/paint-servers.cpp index baabe271e..b34eeb67a 100644 --- a/src/ui/dialog/paint-servers.cpp +++ b/src/ui/dialog/paint-servers.cpp @@ -351,7 +351,7 @@ void PaintServersDialog::load_document(SPDocument *document) void PaintServersDialog::load_current_document(SPObject * /*object*/, guint /*flags*/) { - PaintServersColumns *columns = getColumns(); + std::unique_ptr<PaintServersColumns> columns(getColumns()); SPDocument *document = desktop->getDocument(); Glib::RefPtr<Gtk::ListStore> current = store[CURRENTDOC]; diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index f290dcab7..6f5c65438 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -192,6 +192,7 @@ void TemplateLoadTab::_refreshTemplatesList() } } if (_tlist_store->children().size() == 1) { + delete item_to_select; item_to_select = new Gtk::TreeIter(_tlist_store->children().begin()); } if (item_to_select) { diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 1028731d2..9199ff4ed 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1023,7 +1023,7 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d n->setType(NODE_SMOOTH, false); } else { Geom::D2< Geom::SBasis > sbasis_inside_nodes; - SPCurve *line_inside_nodes = new SPCurve(); + std::unique_ptr<SPCurve> line_inside_nodes(new SPCurve()); if(second->back()->isDegenerate()){ line_inside_nodes->moveto(n->position()); line_inside_nodes->lineto(second->position()); @@ -1311,7 +1311,7 @@ Geom::Point PathManipulator::_bsplineHandleReposition(Handle *h,double pos){ Geom::Point ret = h->position(); Node *n = h->parent(); Geom::D2< Geom::SBasis > sbasis_inside_nodes; - SPCurve *line_inside_nodes = new SPCurve(); + std::unique_ptr<SPCurve> line_inside_nodes(new SPCurve()); Node * next_node = nullptr; next_node = n->nodeToward(h); if(next_node && pos != NO_POWER){ diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 84297a0c1..9b25335d6 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -1470,7 +1470,7 @@ void PenTool::_bsplineSpiroMotion(guint const state){ using Geom::Y; if(this->red_curve->is_unset()) return; this->npoints = 5; - SPCurve *tmp_curve = new SPCurve(); + std::unique_ptr<SPCurve> tmp_curve(new SPCurve()); this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); this->p[2] = Geom::Point(this->p[2][X] + HANDLE_CUBIC_GAP,this->p[2][Y] + HANDLE_CUBIC_GAP); if (this->green_curve->is_unset() && !this->sa) { @@ -1480,9 +1480,9 @@ void PenTool::_bsplineSpiroMotion(guint const state){ this->p[2] = this->p[3]; } } else if (!this->green_curve->is_unset()){ - tmp_curve = this->green_curve->copy(); + tmp_curve.reset(this->green_curve->copy()); } else { - tmp_curve = this->sa_overwrited->copy(); + tmp_curve.reset(this->sa_overwrited->copy()); } if ((state & GDK_MOD1_MASK ) && previous != Geom::Point(0,0)) { //ALT drag this->p[0] = this->p[0] + (this->p[3] - previous); @@ -1591,16 +1591,16 @@ void PenTool::_bsplineSpiroEndAnchorOn() using Geom::Y; this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); this->p[2] = Geom::Point(this->p[2][X] + HANDLE_CUBIC_GAP,this->p[2][Y] + HANDLE_CUBIC_GAP); - SPCurve *tmp_curve; - SPCurve *last_segment = new SPCurve(); + std::unique_ptr<SPCurve> tmp_curve(new SPCurve()); + std::unique_ptr<SPCurve> last_segment(new SPCurve()); Geom::Point point_c(0,0); if( this->green_anchor && this->green_anchor->active ){ - tmp_curve = this->green_curve->create_reverse(); + tmp_curve.reset(this->green_curve->create_reverse()); if(this->green_curve->get_segment_count()==0){ return; } } else if(this->sa){ - tmp_curve = this->sa_overwrited->copy()->create_reverse(); + tmp_curve.reset(this->sa_overwrited->copy()->create_reverse()); }else{ return; } @@ -1619,14 +1619,14 @@ void PenTool::_bsplineSpiroEndAnchorOn() last_segment->lineto(*tmp_curve ->last_point()); } if( tmp_curve ->get_segment_count() == 1){ - tmp_curve = last_segment; + tmp_curve = std::move(last_segment); }else{ //we eliminate the last segment tmp_curve ->backspace(); //and we add it again with the recreation - tmp_curve ->append_continuous(last_segment, 0.0625); + tmp_curve ->append_continuous(last_segment.get(), 0.0625); } - tmp_curve = tmp_curve ->create_reverse(); + tmp_curve.reset(tmp_curve ->create_reverse()); if( this->green_anchor && this->green_anchor->active ) { this->green_curve->reset(); @@ -1635,22 +1635,21 @@ void PenTool::_bsplineSpiroEndAnchorOn() this->sa_overwrited->reset(); this->sa_overwrited = tmp_curve->copy(); } - tmp_curve->unref(); } void PenTool::_bsplineSpiroEndAnchorOff() { - SPCurve *tmp_curve; - SPCurve *last_segment = new SPCurve(); + std::unique_ptr<SPCurve> tmp_curve(new SPCurve()); + std::unique_ptr<SPCurve> last_segment(new SPCurve()); this->p[2] = this->p[3]; if( this->green_anchor && this->green_anchor->active ){ - tmp_curve = this->green_curve->create_reverse(); + tmp_curve.reset(this->green_curve->create_reverse()); if(this->green_curve->get_segment_count()==0){ return; } } else if(this->sa){ - tmp_curve = this->sa_overwrited->copy()->create_reverse(); + tmp_curve.reset(this->sa_overwrited->copy()->create_reverse()); }else{ return; } @@ -1663,14 +1662,14 @@ void PenTool::_bsplineSpiroEndAnchorOff() last_segment->lineto(*tmp_curve ->last_point()); } if( tmp_curve ->get_segment_count() == 1){ - tmp_curve = last_segment; + tmp_curve = std::move(last_segment); }else{ //we eliminate the last segment tmp_curve ->backspace(); //and we add it again with the recreation - tmp_curve ->append_continuous(last_segment, 0.0625); + tmp_curve ->append_continuous(last_segment.get(), 0.0625); } - tmp_curve = tmp_curve ->create_reverse(); + tmp_curve.reset(tmp_curve ->create_reverse()); if( this->green_anchor && this->green_anchor->active ) { @@ -1680,7 +1679,6 @@ void PenTool::_bsplineSpiroEndAnchorOff() this->sa_overwrited->reset(); this->sa_overwrited = tmp_curve->copy(); } - tmp_curve->unref(); } //prepares the curves for its transformation into BSpline curve. @@ -1694,6 +1692,7 @@ void PenTool::_bsplineSpiroBuild() SPCurve *curve = new SPCurve(); //If we continuate the existing curve we add it at the start if(this->sa && !this->sa->curve->is_unset()){ + delete curve; curve = this->sa_overwrited->copy(); } @@ -1862,13 +1861,13 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) { if(!this->green_curve->is_unset() && !Geom::are_near(*this->green_curve->last_point(),this->p[0])) { - SPCurve *lsegment = new SPCurve(); + std::unique_ptr<SPCurve> lsegment(new SPCurve()); Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*this->green_curve->last_segment()); if (cubic) { lsegment->moveto((*cubic)[0]); lsegment->curveto((*cubic)[1], this->p[0] - ((*cubic)[2] - (*cubic)[3]), *this->red_curve->first_point()); this->green_curve->backspace(); - this->green_curve->append_continuous(lsegment, 0.0625); + this->green_curve->append_continuous(lsegment.get(), 0.0625); } } this->green_curve->append_continuous(this->red_curve, 0.0625); diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp index cb5726c6f..fa8b6745e 100644 --- a/src/widgets/sp-xmlview-tree.cpp +++ b/src/widgets/sp-xmlview-tree.cpp @@ -160,7 +160,6 @@ void sp_xmlview_tree_destroy(GtkWidget * object) GtkTreeRowReference * add_node (SPXMLViewTree * tree, GtkTreeIter *parent, GtkTreeIter *before, Inkscape::XML::Node * repr) { - NodeData * data = nullptr; const Inkscape::XML::NodeEventVector * vec; static const gchar *default_text[] = { "???" }; @@ -180,7 +179,7 @@ add_node (SPXMLViewTree * tree, GtkTreeIter *parent, GtkTreeIter *before, Inksca GtkTreeRowReference *rowref = tree_iter_to_ref (tree, &iter); - data = node_data_new (tree, &iter, rowref, repr); + NodeData * data = node_data_new (tree, &iter, rowref, repr); g_assert (data != nullptr); |
