From 68f5a2a9036aa06813c6f3ae5eb5c3743b8325ac Mon Sep 17 00:00:00 2001 From: joncruz Date: Tue, 29 Sep 2009 03:07:09 +0000 Subject: [PATCH] Fixed leaking memory and added proper name fallback. Applies modified patch and addresses bug #436151. --- src/file.cpp | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index ef9706c33..4964d30d5 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -138,31 +138,48 @@ sp_file_new(const Glib::ustring &templ) return dt; } -SPDesktop* -sp_file_new_default() +SPDesktop* sp_file_new_default() { std::list sources; sources.push_back( profile_path("templates") ); // first try user's local dir sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir - - while (!sources.empty()) { - gchar *dirname = sources.front(); - if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { - - // TRANSLATORS: default.svg is localizable - this is the name of the default document - // template. This way you can localize the default pagesize, translate the name of - // the default layer, etc. If you wish to localize this file, please create a - // localized share/templates/default.xx.svg file, where xx is your language code. - char *default_template = g_build_filename(dirname, _("default.svg"), NULL); - if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) { - return sp_file_new(default_template); + std::list baseNames; + gchar const* localized = _("default.svg"); + if (strcmp("default.svg", localized) != 0) { + baseNames.push_back(localized); + } + baseNames.push_back("default.svg"); + gchar *foundTemplate = 0; + + for (std::list::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) { + for (std::list::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) { + gchar *dirname = *it; + if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { + + // TRANSLATORS: default.svg is localizable - this is the name of the default document + // template. This way you can localize the default pagesize, translate the name of + // the default layer, etc. If you wish to localize this file, please create a + // localized share/templates/default.xx.svg file, where xx is your language code. + char *tmp = g_build_filename(dirname, *nameIt, NULL); + if (Inkscape::IO::file_test(tmp, G_FILE_TEST_IS_REGULAR)) { + foundTemplate = tmp; + } else { + g_free(tmp); + } } } - g_free(dirname); - sources.pop_front(); } - return sp_file_new(""); + for (std::list::iterator it = sources.begin(); it != sources.end(); ++it) { + g_free(*it); + } + + SPDesktop* desk = sp_file_new(foundTemplate ? foundTemplate : ""); + if (foundTemplate) { + g_free(foundTemplate); + foundTemplate = 0; + } + return desk; } -- 2.30.2