From ce5229be907e72e96c711ae37bcb5919f7b31c3b Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Mar 2014 21:21:12 +0100 Subject: sp_selected_path_combine: simplify code, prevent memleak waiting to happen upon refactoring (bzr r13199) --- src/path-chemistry.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/path-chemistry.cpp') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 5f478435d..b613e6afa 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -83,10 +83,10 @@ sp_selected_path_combine(SPDesktop *desktop) gint position = 0; char const *id = NULL; char const *transform = NULL; - gchar *style = NULL; - gchar *path_effect = NULL; + Glib::ustring style; + Glib::ustring path_effect; - SPCurve* curve = 0; + SPCurve* curve = NULL; SPItem *first = NULL; Inkscape::XML::Node *parent = NULL; @@ -114,18 +114,15 @@ sp_selected_path_combine(SPDesktop *desktop) id = first->getRepr()->attribute("id"); transform = first->getRepr()->attribute("transform"); // FIXME: merge styles of combined objects instead of using the first one's style - style = g_strdup(first->getRepr()->attribute("style")); - path_effect = g_strdup(first->getRepr()->attribute("inkscape:path-effect")); + style = first->getRepr()->attribute("style"); + path_effect = first->getRepr()->attribute("inkscape:path-effect"); //c->transform(item->transform); curve = c; } else { c->transform(item->getRelativeTransform(first)); curve->append(c, false); c->unref(); - } - // unless this is the topmost object, - if (item != first) { // reduce position only if the same parent if (item->getRepr()->parent() == parent) { position--; @@ -149,16 +146,14 @@ sp_selected_path_combine(SPDesktop *desktop) if (transform) { repr->setAttribute("transform", transform); } - repr->setAttribute("style", style); - g_free(style); + repr->setAttribute("style", style.c_str()); - repr->setAttribute("inkscape:path-effect", path_effect); - g_free(path_effect); + repr->setAttribute("inkscape:path-effect", path_effect.c_str()); // set path data corresponding to new curve gchar *dstring = sp_svg_write_path(curve->get_pathvector()); curve->unref(); - if (path_effect) { + if (!path_effect.empty()) { repr->setAttribute("inkscape:original-d", dstring); } else { repr->setAttribute("d", dstring); -- cgit v1.2.3 From 53d32bfc98a277a724732a0bc9df27f0992db125 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Mar 2014 22:26:34 +0100 Subject: add convenience functions to deal with Glib::ustrings for setting repr attributes (bzr r13203) --- src/path-chemistry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/path-chemistry.cpp') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index b613e6afa..22928ccdd 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -146,9 +146,9 @@ sp_selected_path_combine(SPDesktop *desktop) if (transform) { repr->setAttribute("transform", transform); } - repr->setAttribute("style", style.c_str()); + repr->setAttribute("style", style); - repr->setAttribute("inkscape:path-effect", path_effect.c_str()); + repr->setAttribute("inkscape:path-effect", path_effect); // set path data corresponding to new curve gchar *dstring = sp_svg_write_path(curve->get_pathvector()); -- cgit v1.2.3 From 7f2cbea1d2c460849d1c854f4b6a1f41bf9d07b2 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 25 Mar 2014 19:26:56 +0100 Subject: fix crash introduced in rev. 13199. (revert the change to Glib::string (crashes on nullptr init), but keep the memleak fix) Fixed bugs: - https://launchpad.net/bugs/1297174 (bzr r13210) --- src/path-chemistry.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/path-chemistry.cpp') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 22928ccdd..d355b49fe 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -83,8 +83,8 @@ sp_selected_path_combine(SPDesktop *desktop) gint position = 0; char const *id = NULL; char const *transform = NULL; - Glib::ustring style; - Glib::ustring path_effect; + char const *style = NULL; + char const *path_effect = NULL; SPCurve* curve = NULL; SPItem *first = NULL; @@ -153,7 +153,7 @@ sp_selected_path_combine(SPDesktop *desktop) // set path data corresponding to new curve gchar *dstring = sp_svg_write_path(curve->get_pathvector()); curve->unref(); - if (!path_effect.empty()) { + if (path_effect) { repr->setAttribute("inkscape:original-d", dstring); } else { repr->setAttribute("d", dstring); @@ -365,7 +365,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec items = items->next) { SPItem *item = SP_ITEM(items->data); - SPDocument *document = item->document; + SPDocument *document = item->document; if ( skip_all_lpeitems && SP_IS_LPE_ITEM(item) && @@ -443,12 +443,12 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec parent->appendChild(repr); SPObject* newObj = document->getObjectByRepr(repr); if (title && newObj) { - newObj->setTitle(title); - g_free(title); + newObj->setTitle(title); + g_free(title); } if (desc && newObj) { - newObj->setDesc(desc); - g_free(desc); + newObj->setDesc(desc); + g_free(desc); } // move to the saved position -- cgit v1.2.3