From e82db5320b8f94be360d5892c08eadcf84c4d7e1 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 8 Nov 2014 22:35:22 +0100 Subject: 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 new_pair(name_copy, filter->_image_number_next++); // post-increment number_next pair::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) --- src/sp-filter.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/sp-filter.cpp') 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 new_pair(name_copy, value); pair::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; -- cgit v1.2.3