Branch: refs/heads/master Author: Pavel Roschin roshin@scriptumplus.ru Committer: Frank Lanitz frank@frank.uvena.de Date: Sat, 12 Apr 2014 17:44:41 UTC Commit: 4c4bcb5c2fa498b5f0bcefa20822dd252c4c0c8f https://github.com/geany/geany-plugins/commit/4c4bcb5c2fa498b5f0bcefa20822dd...
Log Message: ----------- Auto-close: fix possible crash at exit
Autoclose plugin uses plugin_signal_connect to connect to Scintilla widget. This may cause a crash on old glib because widget is a short-lived object. Now behavior changed: autoclose uses raw g_signal_connect call and calls g_signal_handler_disconnect manually. But this may cause a crash with old Geany versions and works good only with last revision of Geany.
Modified Paths: -------------- autoclose/src/autoclose.c
Modified: autoclose/src/autoclose.c 39 files changed, 34 insertions(+), 5 deletions(-) =================================================================== @@ -87,6 +87,7 @@ typedef struct { static AutocloseInfo *ac_info = NULL;
typedef struct { + gulong notify_handler[2]; /* used to place the caret after autoclosed items on tab (similar to eclipse) */ gint jump_on_tab; /* used to reset jump_on_tab when needed */ @@ -799,6 +800,7 @@ on_sci_notify(ScintillaObject *sci, gint scn, SCNotification *nt, gpointer user_ data->last_line = new_line; }
+ static void on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data) { @@ -808,15 +810,41 @@ on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data)
sci = doc->editor->sci; data = g_new0(AutocloseUserData, 1); + g_return_if_fail(data); data->doc = doc; - plugin_signal_connect(geany_plugin, G_OBJECT(sci), "sci-notify", - FALSE, G_CALLBACK(on_sci_notify), data); - plugin_signal_connect(geany_plugin, G_OBJECT(sci), "key-press-event", - FALSE, G_CALLBACK(on_key_press), data); + data->notify_handler[0] = g_signal_connect(G_OBJECT(sci), "sci-notify", + G_CALLBACK(on_sci_notify), data); + data->notify_handler[1] = g_signal_connect(G_OBJECT(sci), "key-press-event", + G_CALLBACK(on_key_press), data); /* This will free the data when the sci is destroyed */ g_object_set_data_full(G_OBJECT(sci), "autoclose-userdata", data, g_free); }
+static void +autoclose_handlers_cleanup(void) +{ + gint i; + + foreach_document(i) + { + gint j; + gpointer data; + ScintillaObject *sci; + AutocloseUserData *autoclose_data; + + sci = documents[i]->editor->sci; + data = g_object_get_data(G_OBJECT(sci), "autoclose-userdata"); + if(!data) + continue; + autoclose_data = (AutocloseUserData*)data; + for(j = 0; j < 2; j++) + { + gulong handler = autoclose_data->notify_handler[j]; + g_signal_handler_disconnect(sci, handler); + } + } +} + PluginCallback plugin_callbacks[] = { { "document-open", (GCallback) &on_document_open, FALSE, NULL }, @@ -885,7 +913,7 @@ configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data) void plugin_init(G_GNUC_UNUSED GeanyData *data) { - int i; + guint i; foreach_document(i) { on_document_open(NULL, documents[i], NULL); @@ -1100,6 +1128,7 @@ plugin_configure(GtkDialog *dialog) void plugin_cleanup(void) { + autoclose_handlers_cleanup(); g_free(ac_info->config_file); g_free(ac_info); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).