talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 2c781ca221d8b1a25d382063c8ff2e84d4f25be6
parent f54e21bebac3b16c6fbcb149d65fc89da7558ab8
Author: Ricardo Mones <ricardo@mones.org>
Date:   Tue, 22 Sep 2015 14:57:17 +0200

Libravatar: remove hooks on failed init

Diffstat:
Msrc/plugins/libravatar/libravatar.c | 28++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/plugins/libravatar/libravatar.c b/src/plugins/libravatar/libravatar.c @@ -347,6 +347,20 @@ static void missing_cache_done() } } +static void unregister_hooks() +{ + if (render_hook_id != -1) { + hooks_unregister_hook(AVATAR_IMAGE_RENDER_HOOKLIST, + render_hook_id); + render_hook_id = -1; + } + if (update_hook_id != -1) { + hooks_unregister_hook(AVATAR_HEADER_UPDATE_HOOKLIST, + update_hook_id); + update_hook_id = -1; + } +} + /** * Initialize plugin. * @@ -372,11 +386,13 @@ gint plugin_init(gchar **error) libravatar_image_render_hook, NULL); if (render_hook_id == -1) { + unregister_hooks(); *error = g_strdup(_("Failed to register avatar image render hook")); return -1; } /* cache dir */ if (cache_dir_init() == -1) { + unregister_hooks(); *error = g_strdup(_("Failed to create avatar image cache directory")); return -1; } @@ -386,6 +402,7 @@ gint plugin_init(gchar **error) curl_global_init(CURL_GLOBAL_DEFAULT); /* missing cache */ if (missing_cache_init() == -1) { + unregister_hooks(); *error = g_strdup(_("Failed to load missing items cache")); return -1; } @@ -402,16 +419,7 @@ gint plugin_init(gchar **error) */ gboolean plugin_done(void) { - if (render_hook_id != -1) { - hooks_unregister_hook(AVATAR_IMAGE_RENDER_HOOKLIST, - render_hook_id); - render_hook_id = -1; - } - if (update_hook_id != -1) { - hooks_unregister_hook(AVATAR_HEADER_UPDATE_HOOKLIST, - update_hook_id); - update_hook_id = -1; - } + unregister_hooks(); libravatar_prefs_done(); missing_cache_done(); if (cache_dir != NULL)