From 0e00c6b605bc5e117d71c37c8bab0e7d68c64c17 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Thu, 2 Mar 2023 22:24:52 +0800 Subject: [PATCH] Coverity: fix dialog dereference null return value This patch is making sure defaultPath returns from FindImage() is not null and freeing the variables. --- src/dialog.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/dialog.c b/src/dialog.c index ff1bd144..0561dc1f 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -1103,14 +1103,16 @@ Bool wIconChooserDialog(WScreen *scr, char **file, const char *instance, const c } else { defaultPath = FindImage(wPreferences.icon_path, *file); wantedPath = WMGetTextFieldText(panel->fileField); - /* if the file is not the default, use full path */ - if (strcmp(wantedPath, defaultPath) != 0) { - *file = wantedPath; - } else { - *file = wstrdup(*file); - wfree(wantedPath); + if (defaultPath) { + /* if the file is not the default, use full path */ + if (strcmp(wantedPath, defaultPath) != 0) { + *file = wstrdup(wantedPath); + } else { + *file = wstrdup(*file); + } + wfree(defaultPath); } - wfree(defaultPath); + wfree(wantedPath); } } else { *file = NULL;