summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2014-11-08 21:35:22 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2014-11-08 21:35:22 +0000
commite82db5320b8f94be360d5892c08eadcf84c4d7e1 (patch)
treea3f5eec3076d4e28eee21e37a110c6f4e98e6a76 /src
parentfix missing assignment to variable. (diff)
downloadinkscape-e82db5320b8f94be360d5892c08eadcf84c4d7e1.tar.gz
inkscape-e82db5320b8f94be360d5892c08eadcf84c4d7e1.zip
sp-filter: fix memory leak when trying to set a duplicate name for an image.
This function could use more cleanup, but because I can't test now, I will write it down here: int sp_filter_set_image_name(SPFilter *filter, gchar const *name) { gchar *name_copy = strdup(name); pair<gchar*,int> new_pair(name_copy, filter->_image_number_next++); // post-increment number_next pair<map<gchar*,int,ltstr>::iterator,bool> ret = filter->_image_name->insert(new_pair); if (ret.second == false) { // The element is not inserted (because an element with the same key was already in the map) // Therefore, free the memory allocated for the new entry: free(name_copy); } return (*ret.first).second; } (bzr r13684)
Diffstat (limited to 'src')
-rw-r--r--src/sp-filter.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp
index 9a184952c..9cb33a6f3 100644
--- a/src/sp-filter.cpp
+++ b/src/sp-filter.cpp
@@ -465,6 +465,10 @@ int sp_filter_set_image_name(SPFilter *filter, gchar const *name) {
pair<gchar*,int> new_pair(name_copy, value);
pair<map<gchar*,int,ltstr>::iterator,bool> ret = filter->_image_name->insert(new_pair);
if (ret.second == false) {
+ // The element is not inserted (because an element with the same key was already in the map)
+ // Therefore, free the memory allocated for the new entry:
+ free(name_copy);
+
return (*ret.first).second;
}
return value;