Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Tue, 24 Sep 2013 22:00:44 UTC Commit: 1ab97fe2e0c4222900bb6e4e8d54655cfefd8756 https://github.com/geany/geany/commit/1ab97fe2e0c4222900bb6e4e8d54655cfefd87...
Log Message: ----------- Plug a memory leak when reading misnamed tag files
Don't leak the file name if we can't determine to which filetype it belongs. Thanks to Pavel Roschin for spotting this.
Also, remove an useless second function indirection that simply made the code harder to understand. This will make Matthew happy ;)
Modified Paths: -------------- src/symbols.c
Modified: src/symbols.c 46 files changed, 22 insertions(+), 24 deletions(-) =================================================================== @@ -1862,37 +1862,16 @@ void symbols_show_load_tags_dialog(void) }
-static void detect_tag_files(const GSList *file_list) -{ - const GSList *node; - - for (node = file_list; node != NULL; node = g_slist_next(node)) - { - gchar *fname = node->data; - gchar *utf8_fname = utils_get_utf8_from_locale(fname); - GeanyFiletype *ft = detect_global_tags_filetype(utf8_fname); - - g_free(utf8_fname); - - if (FILETYPE_ID(ft) != GEANY_FILETYPES_NONE) - ft->priv->tag_files = g_slist_prepend(ft->priv->tag_files, fname); - else - geany_debug("Unknown filetype for file '%s'.", fname); - } -} - - static void init_user_tags(void) { GSList *file_list = NULL, *list = NULL; + const GSList *node; gchar *dir;
dir = g_build_filename(app->configdir, "tags", NULL); /* create the user tags dir for next time if it doesn't exist */ if (! g_file_test(dir, G_FILE_TEST_IS_DIR)) - { utils_mkdir(dir, FALSE); - } file_list = utils_get_file_list_full(dir, TRUE, FALSE, NULL);
SETPTR(dir, g_build_filename(app->datadir, "tags", NULL)); @@ -1900,8 +1879,27 @@ static void init_user_tags(void) g_free(dir);
file_list = g_slist_concat(file_list, list); - detect_tag_files(file_list); - /* don't need to delete list contents because they are stored in ft->priv->tag_files */ + + /* populate the filetype-specific tag files lists */ + for (node = file_list; node != NULL; node = node->next) + { + gchar *fname = node->data; + gchar *utf8_fname = utils_get_utf8_from_locale(fname); + GeanyFiletype *ft = detect_global_tags_filetype(utf8_fname); + + g_free(utf8_fname); + + if (FILETYPE_ID(ft) != GEANY_FILETYPES_NONE) + ft->priv->tag_files = g_slist_prepend(ft->priv->tag_files, fname); + else + { + geany_debug("Unknown filetype for file '%s'.", fname); + g_free(fname); + } + } + + /* don't need to delete list contents because they are now stored in + * ft->priv->tag_files */ g_slist_free(file_list); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).