From 058568eab3a59c9aa6e80f9aefbce84ee57ea1bc Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 24 Oct 2025 23:12:58 +0800 Subject: [PATCH] [gnc-plugin-page-report] plug char* leaks also move a few lines later to avoid confirming double filepath != nullptr confirmation --- gnucash/gnome/gnc-plugin-page-report.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnucash/gnome/gnc-plugin-page-report.cpp b/gnucash/gnome/gnc-plugin-page-report.cpp index 6f2743b4c5..ac835affdf 100644 --- a/gnucash/gnome/gnc-plugin-page-report.cpp +++ b/gnucash/gnome/gnc-plugin-page-report.cpp @@ -1604,12 +1604,6 @@ gnc_get_export_filename (SCM choice, GtkWindow *parent) filepath = gnc_file_dialog (parent, title, nullptr, default_dir, GNC_FILE_DIALOG_EXPORT); - if (filepath != nullptr) // test for cancel pressed - { - /* Try to test for extension on file name, add if missing */ - if (g_strrstr(filepath, ".") == nullptr) - filepath = g_strconcat(filepath, ".", g_ascii_strdown(type, strlen(type)), nullptr); - } g_free (type); g_free (title); g_free (default_dir); @@ -1617,6 +1611,16 @@ gnc_get_export_filename (SCM choice, GtkWindow *parent) if (!filepath) return nullptr; + /* Try to test for extension on file name, add if missing */ + if (strchr (filepath, '.') == nullptr) + { + char* extension = g_ascii_strdown (type, -1); + char* newpath = g_strdup_printf ("%s.%s", filepath, extension); + g_free (extension); + g_free (filepath); + filepath = newpath; + } + default_dir = g_path_get_dirname(filepath); gnc_set_default_directory (GNC_PREFS_GROUP_REPORT, default_dir); g_free(default_dir);