From: Christophe CURIS <christophe.cu...@free.fr> Coverity pointed that in the typical code path the function FindImage would be called twice, leading in leakage of the allocated result from the first call.
This patch updates the condition so that the case won't arise. Signed-off-by: Christophe CURIS <christophe.cu...@free.fr> --- src/wdefaults.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/wdefaults.c b/src/wdefaults.c index 3371e71..c2d9eb8 100644 --- a/src/wdefaults.c +++ b/src/wdefaults.c @@ -375,8 +375,8 @@ static WMPropList *get_generic_value(const char *instance, const char *class, char *get_icon_filename(const char *winstance, const char *wclass, const char *command, Bool default_icon) { - char *file_name = NULL; - char *file_path = NULL; + char *file_name; + char *file_path; /* Get the file name of the image, using instance and class */ file_name = wDefaultGetIconFile(winstance, wclass, default_icon); @@ -384,30 +384,33 @@ char *get_icon_filename(const char *winstance, const char *wclass, const char *c /* Check if the file really exists in the disk */ if (file_name) file_path = FindImage(wPreferences.icon_path, file_name); + else + file_path = NULL; /* If the specific icon filename is not found, and command is specified, * then include the .app icons and re-do the search. */ - if ((!file_name || !file_path ) && command) { + if (!file_path && command) { wApplicationExtractDirPackIcon(command, winstance, wclass); file_name = wDefaultGetIconFile(winstance, wclass, False); - } - - /* Get the full path for the image file */ - if (file_name) { - file_path = FindImage(wPreferences.icon_path, file_name); - if (!file_path) - wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name); + if (file_name) { + file_path = FindImage(wPreferences.icon_path, file_name); + if (!file_path) + wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name); - /* FIXME: Here, if file_path don't exists, then the icon is in the - * "icon database" (w_global.domain.window_attr->dictionary), but the icon - * is not en disk. Therefore, we should remove it from the icon - * database. Is possible to do that using wDefaultChangeIcon() */ - - /* Don't wfree(file_name) here, because is a pointer to the icon - * dictionary (w_global.domain.window_attr->dictionary) value. */ + /* FIXME: Here, if file_path does not exist then the icon is still in the + * "icon database" (w_global.domain.window_attr->dictionary), but the file + * for the icon is no more on disk. Therefore, we should remove it from the + * database. Is possible to do that using wDefaultChangeIcon() */ + } } + /* + * Don't wfree(file_name) because it is a direct pointer inside the icon + * dictionary (w_global.domain.window_attr->dictionary) and not a result + * allocated with wstrdup() + */ + if (!file_path && default_icon) file_path = get_default_image_path(); -- 2.1.1 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.