From: Daniel Carl Date: Sun, 16 Nov 2014 23:23:13 +0000 (+0100) Subject: Fix segfault on quit by control fifo (#144). X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=1eab14a56e021d1f0926ce314b63a973b7fc415e;p=vimb.git Fix segfault on quit by control fifo (#144). If vimb is closed by the fifo with `echo ":q\r" >> {fifo}` or `echo '' >> {fifo}`, vimb crashed because of a too early cleanup during allready active main loop. The cleanup code is now called right after the main loop is killed. --- diff --git a/src/main.c b/src/main.c index 301fcf1..5bd603d 100644 --- a/src/main.c +++ b/src/main.c @@ -115,6 +115,7 @@ static void register_cleanup(void); static gboolean hide_message(); static void set_status(const StatusType status); static void input_print(gboolean force, const MessageType type, gboolean hide, const char *message); +static void vb_cleanup(void); void vb_echo_force(const MessageType type, gboolean hide, const char *error, ...) { @@ -419,33 +420,6 @@ void vb_quit(gboolean force) g_file_set_contents(vb.files[FILES_CLOSED], vb.state.uri, -1, NULL); } - completion_clean(); - - webkit_web_view_stop_loading(vb.gui.webview); - - map_cleanup(); - mode_cleanup(); - setting_cleanup(); - history_cleanup(); - session_cleanup(); - register_cleanup(); -#ifdef FEATURE_AUTOCMD - autocmd_cleanup(); -#endif -#ifdef FEATURE_ARH - arh_free(vb.config.autoresponseheader); -#endif -#ifdef FEATURE_FIFO - io_cleanup(); -#endif - - g_slist_free_full(vb.config.cmdargs, g_free); - - for (int i = 0; i < FILES_LAST; i++) { - g_free(vb.files[i]); - vb.files[i] = NULL; - } - gtk_main_quit(); } @@ -1522,6 +1496,40 @@ static void session_request_queued_cb(SoupSession *session, SoupMessage *msg, gp } #endif +/** + * Free some memory when vimb is quit. + */ +static void vb_cleanup(void) +{ + + completion_clean(); + + webkit_web_view_stop_loading(vb.gui.webview); + + map_cleanup(); + mode_cleanup(); + setting_cleanup(); + history_cleanup(); + session_cleanup(); + register_cleanup(); +#ifdef FEATURE_AUTOCMD + autocmd_cleanup(); +#endif +#ifdef FEATURE_ARH + arh_free(vb.config.autoresponseheader); +#endif +#ifdef FEATURE_FIFO + io_cleanup(); +#endif + + g_slist_free_full(vb.config.cmdargs, g_free); + + for (int i = 0; i < FILES_LAST; i++) { + g_free(vb.files[i]); + vb.files[i] = NULL; + } +} + static gboolean autocmdOptionArgFunc(const gchar *option_name, const gchar *value, gpointer data, GError **error) { vb.config.cmdargs = g_slist_append(vb.config.cmdargs, g_strdup(value)); @@ -1601,5 +1609,8 @@ int main(int argc, char *argv[]) /* Run the main GTK+ event loop */ gtk_main(); + /* cleanup memory */ + vb_cleanup(); + return EXIT_SUCCESS; }