more error handling

This commit is contained in:
Sebastian Ramacher 2012-01-13 18:07:21 +01:00
parent 58e25e8733
commit 33173e018e
2 changed files with 9 additions and 6 deletions

View file

@ -31,22 +31,21 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil
char* name = NULL; char* name = NULL;
while ((name = (char*) g_dir_read_name(dir)) != NULL) { while ((name = (char*) g_dir_read_name(dir)) != NULL) {
char* e_name = g_filename_display_name(name); char* e_name = g_filename_display_name(name);
int e_length = strlen(e_name);
if (e_name == NULL) { 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, if ((current_file_length > e_length) || strncmp(current_file, e_name,
current_file_length)) { current_file_length)) {
g_free(e_name); g_free(e_name);
continue; goto error_free;
} }
char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name); char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name);
if (full_path == NULL) { if (full_path == NULL) {
g_free(e_name); g_free(e_name);
continue; goto error_free;
} }
if (g_file_test(full_path, G_FILE_TEST_IS_DIR) == true) { 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); g_dir_close(dir);
return res; return res;
error_free:
girara_list_free(res);
return NULL;
} }
girara_completion_t* girara_completion_t*

View file

@ -37,7 +37,7 @@ void
zathura_document_plugins_load(zathura_t* zathura) zathura_document_plugins_load(zathura_t* zathura)
{ {
GIRARA_LIST_FOREACH(zathura->plugins.path, char*, iter, plugindir) GIRARA_LIST_FOREACH(zathura->plugins.path, char*, iter, plugindir)
/* TODO: rewrite with GDir */
/* read all files in the plugin directory */ /* read all files in the plugin directory */
DIR* dir = opendir(plugindir); DIR* dir = opendir(plugindir);
if (dir == NULL) { if (dir == NULL) {