[gnc-plugin-page-report] avoid UAF from 058568eab3

This commit is contained in:
Christopher Lam committed 2025-11-07 08:39:15 +08:00
1 parent 7bdf31f9d3
commit ac92388cad
1 file changed
+8 -8
+8 -8
View File
@@ -1604,15 +1604,8 @@ gnc_get_export_filename (SCM choice, GtkWindow *parent)
filepath = gnc_file_dialog (parent, title, nullptr, default_dir,
GNC_FILE_DIALOG_EXPORT);
g_free (type);
g_free (title);
g_free (default_dir);
if (!filepath)
return nullptr;
/* Try to test for extension on file name, add if missing */
if (strchr (filepath, '.') == nullptr)
if (filepath && strchr (filepath, '.') == nullptr)
{
char* extension = g_ascii_strdown (type, -1);
char* newpath = g_strdup_printf ("%s.%s", filepath, extension);
@@ -1621,6 +1614,13 @@ gnc_get_export_filename (SCM choice, GtkWindow *parent)
filepath = newpath;
}
g_free (type);
g_free (title);
g_free (default_dir);
if (!filepath)
return nullptr;
default_dir = g_path_get_dirname(filepath);
gnc_set_default_directory (GNC_PREFS_GROUP_REPORT, default_dir);
g_free(default_dir);