From 33173e018e0b43c51be1474f6c2626dc81fb4549 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 13 Jan 2012 18:07:21 +0100 Subject: [PATCH] more error handling --- completion.c | 13 ++++++++----- document.c | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/completion.c b/completion.c index fd513bc..a0983cb 100644 --- a/completion.c +++ b/completion.c @@ -31,22 +31,21 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { char* e_name = g_filename_display_name(name); - int e_length = strlen(e_name); - if (e_name == NULL) { - continue; + goto error_free; } + int e_length = strlen(e_name); if ((current_file_length > e_length) || strncmp(current_file, e_name, current_file_length)) { g_free(e_name); - continue; + goto error_free; } char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name); if (full_path == NULL) { g_free(e_name); - continue; + goto error_free; } if (g_file_test(full_path, G_FILE_TEST_IS_DIR) == true) { @@ -64,6 +63,10 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil g_dir_close(dir); return res; + +error_free: + girara_list_free(res); + return NULL; } girara_completion_t* diff --git a/document.c b/document.c index 30f906c..758d252 100644 --- a/document.c +++ b/document.c @@ -37,7 +37,7 @@ void zathura_document_plugins_load(zathura_t* zathura) { GIRARA_LIST_FOREACH(zathura->plugins.path, char*, iter, plugindir) - + /* TODO: rewrite with GDir */ /* read all files in the plugin directory */ DIR* dir = opendir(plugindir); if (dir == NULL) {