diff --git a/src/core/wee-network.c b/src/core/wee-network.c index 8ec41e36f..c6c1c7032 100644 --- a/src/core/wee-network.c +++ b/src/core/wee-network.c @@ -67,20 +67,29 @@ const int gnutls_cert_type_prio[] = { GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 }; /* * network_init: init network */ + void network_init () { #ifdef HAVE_GNUTLS - char *CApath, *CApath2; + char *ca_path, *ca_path2; gnutls_global_init (); gnutls_certificate_allocate_credentials (&gnutls_xcred); - - CApath = string_replace (CONFIG_STRING(config_network_gnutls_ca_file), - "~", getenv ("HOME")); - CApath2 = string_replace (CApath, "%h", weechat_home); - - gnutls_certificate_set_x509_trust_file (gnutls_xcred, CApath2, GNUTLS_X509_FMT_PEM); + + ca_path = string_replace (CONFIG_STRING(config_network_gnutls_ca_file), + "~", getenv ("HOME")); + if (ca_path) + { + ca_path2 = string_replace (ca_path, "%h", weechat_home); + if (ca_path2) + { + gnutls_certificate_set_x509_trust_file (gnutls_xcred, ca_path2, + GNUTLS_X509_FMT_PEM); + free (ca_path2); + } + free (ca_path); + } gnutls_certificate_client_set_retrieve_function (gnutls_xcred, &hook_connect_gnutls_set_certificates); network_init_ok = 1; @@ -102,6 +111,7 @@ network_end () #ifdef HAVE_GNUTLS if (network_init_ok) { + network_init_ok = 0; gnutls_certificate_free_credentials (gnutls_xcred); gnutls_global_deinit(); } diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 46511ad87..3a90c6ef9 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -72,8 +72,8 @@ gui_main_pre_init (int *argc, char **argv[]) /* pre-init colors */ gui_color_pre_init (); - /* build empty prefixes (before reading config) */ - gui_chat_prefix_build_empty (); + /* init some variables for chat area */ + gui_chat_init (); } /* @@ -401,8 +401,8 @@ gui_main_end (int clean_exit) /* end color */ gui_color_end (); - /* free chat buffer */ - gui_chat_free_buffer (); + /* free some variables used for chat area */ + gui_chat_end (); } /* end of Curses output */ diff --git a/src/gui/gtk/gui-gtk-main.c b/src/gui/gtk/gui-gtk-main.c index acffeea95..b0fa9ea90 100644 --- a/src/gui/gtk/gui-gtk-main.c +++ b/src/gui/gtk/gui-gtk-main.c @@ -70,8 +70,8 @@ gui_main_pre_init (int *argc, char **argv[]) /* pre-init colors */ gui_color_pre_init (); - /* build empty prefixes (before reading config) */ - gui_chat_prefix_build_empty (); + /* init some variables for chat area */ + gui_chat_init (); /* Initialise Gtk */ gtk_init (argc, argv); @@ -277,7 +277,7 @@ gui_main_end (int clean_exit) /* end color */ gui_color_end (); - /* free chat buffer */ - gui_chat_free_buffer (); + /* free some variables used for chat area */ + gui_chat_end (); } } diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 3a346a52e..110ecd11f 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -55,13 +55,14 @@ struct t_gui_buffer *gui_chat_mute_buffer = NULL; /* mute buffer */ /* - * gui_chat_prefix_build_empty: build empty prefixes - * (called before reading WeeChat config file) + * gui_chat_init: init some variables for chat area + * (called before reading WeeChat config file) */ void -gui_chat_prefix_build_empty () +gui_chat_init () { + /* build empty prefixes */ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR] = strdup (gui_chat_prefix_empty); gui_chat_prefix[GUI_CHAT_PREFIX_NETWORK] = strdup (gui_chat_prefix_empty); gui_chat_prefix[GUI_CHAT_PREFIX_ACTION] = strdup (gui_chat_prefix_empty); @@ -651,15 +652,28 @@ gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) } /* - * gui_chat_free_buffer: free buffer used by chat functions + * gui_chat_end: free some variables allocated for chat area */ void -gui_chat_free_buffer () +gui_chat_end () { + int i; + + /* free buffer used by chat functions */ if (gui_chat_buffer) { free (gui_chat_buffer); gui_chat_buffer = NULL; } + + /* free prefixes */ + for (i = 0; i < GUI_CHAT_NUM_PREFIXES; i++) + { + if (gui_chat_prefix[i]) + { + free (gui_chat_prefix[i]); + gui_chat_prefix[i] = NULL; + } + } } diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index 0cc3caaa9..16c5ae56e 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -57,7 +57,7 @@ extern struct t_gui_buffer *gui_chat_mute_buffer; /* chat functions */ -extern void gui_chat_prefix_build_empty (); +extern void gui_chat_init (); extern void gui_chat_prefix_build (); extern int gui_chat_strlen_screen (const char *string); extern char *gui_chat_string_add_offset (const char *string, int offset); @@ -75,7 +75,7 @@ extern void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, const char *message, ...); extern void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...); -extern void gui_chat_free_buffer (); +extern void gui_chat_end (); /* chat functions (GUI dependent) */