summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2013-01-22 18:45:30 +0000
committerKris <Kris.De.Gussem@hotmail.com>2013-01-22 18:45:30 +0000
commit320281f276981f14d97f7afbd68a6657bc368cf0 (patch)
treedc336a4daf7dfd58e9348ae08f0181a748f57ec9 /src
parentFilters. Add missing inkscape namespace declaration for 'Channel Painting' (diff)
downloadinkscape-320281f276981f14d97f7afbd68a6657bc368cf0.tar.gz
inkscape-320281f276981f14d97f7afbd68a6657bc368cf0.zip
fix possible memory leak
(bzr r12052)
Diffstat (limited to 'src')
-rw-r--r--src/id-clash.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/id-clash.cpp b/src/id-clash.cpp
index 7a1e000fb..36208e6d8 100644
--- a/src/id-clash.cpp
+++ b/src/id-clash.cpp
@@ -36,9 +36,9 @@ struct IdReference {
const char *attr; // property or href-like attribute
};
-typedef std::map<std::string, std::list<IdReference> > refmap_type;
+typedef std::map<Glib::ustring, std::list<IdReference> > refmap_type;
-typedef std::pair<SPObject*, std::string> id_changeitem_type;
+typedef std::pair<SPObject*, Glib::ustring> id_changeitem_type;
typedef std::list<id_changeitem_type> id_changelist_type;
const char *href_like_attributes[] = {
@@ -298,7 +298,7 @@ void
change_def_references(SPObject *from_obj, SPObject *to_obj)
{
refmap_type *refmap = new refmap_type;
- id_changelist_type id_changes;
+ id_changelist_type id_changes; //delete this line
SPDocument *current_doc = from_obj->document;
std::string old_id(from_obj->getId());
@@ -324,9 +324,15 @@ change_def_references(SPObject *from_obj, SPObject *to_obj)
*/
void rename_id(SPObject *elem, Glib::ustring const &new_name)
{
- gchar *id = g_strdup(new_name.c_str());
+ if (new_name.empty()){
+ g_message("Invalid Id, will not change.");
+ return;
+ }
+ gchar *id = g_strdup(new_name.c_str()); //id is not empty here as new_name is check to be not empty
g_strcanon (id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_');
- if (!*id || !isalnum (*id)) {
+ Glib::ustring new_name2 = id; //will not fail as id can not be NULL, see length check on new_name
+ g_free (id);
+ if (!isalnum (new_name2[0])) {
g_message("Invalid Id, will not change.");
return;
}
@@ -337,31 +343,27 @@ void rename_id(SPObject *elem, Glib::ustring const &new_name)
find_references(current_doc->getRoot(), refmap);
std::string old_id(elem->getId());
- std::string new_id(id);
- if (id && current_doc->getObjectById(id)) {
+ if (current_doc->getObjectById(id)) {
// Choose a new ID.
// To try to preserve any meaningfulness that the original ID
// may have had, the new ID is the old ID followed by a hyphen
// and one or more digits.
- new_id += '-';
+ new_name2 += '-';
for (;;) {
- new_id += "0123456789"[std::rand() % 10];
- const char *str = new_id.c_str();
- if (current_doc->getObjectById(str) == NULL)
+ new_name2 += "0123456789"[std::rand() % 10];
+ if (current_doc->getObjectById(new_name2) == NULL)
break;
}
}
// Change to the new ID
- elem->getRepr()->setAttribute("id", new_id.c_str());
+ elem->getRepr()->setAttribute("id", new_name2.c_str());
// Make a note of this change, if we need to fix up refs to it
if (refmap->find(old_id) != refmap->end()) {
id_changes.push_back(id_changeitem_type(elem, old_id));
}
fix_up_refs(refmap, id_changes);
-
- g_free (id);
delete refmap;
}