Revision: 1743 http://geany.svn.sourceforge.net/geany/?rev=1743&view=rev Author: ntrel Date: 2007-07-25 04:59:34 -0700 (Wed, 25 Jul 2007)
Log Message: ----------- Don't destroy plugin_fields->menu_item automatically - plugin_fields should be owned by the plugin, so the plugin is responsible for destroying it, and any other memory it allocated. Print a warning message in debug mode if a plugin has no cleanup() function.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/htmlchars.c trunk/src/plugindata.h trunk/src/plugins.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-25 11:49:11 UTC (rev 1742) +++ trunk/ChangeLog 2007-07-25 11:59:34 UTC (rev 1743) @@ -4,6 +4,12 @@ Translate the HTML Characters plugin. * src/main.c: Set app->debug_mode when GEANY_DEBUG is defined. + * plugins/htmlchars.c, src/plugindata.h, src/plugins.c: + Don't destroy plugin_fields->menu_item automatically - plugin_fields + should be owned by the plugin, so the plugin is responsible for + destroying it, and any other memory it allocated. + Print a warning message in debug mode if a plugin has no cleanup() + function.
2007-07-25 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/plugins/htmlchars.c =================================================================== --- trunk/plugins/htmlchars.c 2007-07-25 11:49:11 UTC (rev 1742) +++ trunk/plugins/htmlchars.c 2007-07-25 11:59:34 UTC (rev 1743) @@ -521,15 +521,17 @@ gtk_container_add(GTK_CONTAINER(plugin_data->tools_menu), demo_item); g_signal_connect(G_OBJECT(demo_item), "activate", G_CALLBACK(item_activate), NULL);
- // let Geany remove the menu item when the plugin is unloaded + // disable menu_item when there are no documents open plugin_fields->menu_item = demo_item; plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE; }
-/* Destroy static widgets */ +/* Destroy widgets */ void cleanup() { + gtk_widget_destroy(plugin_fields->menu_item); + if (sc_dialog != NULL) gtk_widget_destroy(sc_dialog); }
Modified: trunk/src/plugindata.h =================================================================== --- trunk/src/plugindata.h 2007-07-25 11:49:11 UTC (rev 1742) +++ trunk/src/plugindata.h 2007-07-25 11:59:34 UTC (rev 1743) @@ -41,7 +41,8 @@ * Called after loading the plugin. * * void cleanup() - * Called before unloading the plugin. + * Called before unloading the plugin. Required for normal plugins - it should undo + * everything done in init() - e.g. destroy menu items, free memory. */
@@ -98,7 +99,7 @@ typedef struct PluginFields { PluginFlags flags; - GtkWidget *menu_item; // (optional) widget to be destroyed after unloading the plugin + GtkWidget *menu_item; // required if using PLUGIN_IS_DOCUMENT_SENSITIVE, ignored otherwise } PluginFields;
Modified: trunk/src/plugins.c =================================================================== --- trunk/src/plugins.c 2007-07-25 11:49:11 UTC (rev 1742) +++ trunk/src/plugins.c 2007-07-25 11:59:34 UTC (rev 1743) @@ -214,6 +214,12 @@
g_module_symbol(module, "init", (void *) &plugin->init); g_module_symbol(module, "cleanup", (void *) &plugin->cleanup); + if (plugin->init != NULL && plugin->cleanup == NULL) + { + if (app->debug_mode) + g_warning("Plugin '%s' has no cleanup() function - there may be memory leaks!", + info()->name); + }
if (plugin->init) plugin->init(&plugin->data); @@ -239,11 +245,6 @@ if (plugin->cleanup) plugin->cleanup();
- if (plugin->fields.menu_item != NULL) - { - gtk_widget_destroy(plugin->fields.menu_item); - } - if (! g_module_close(plugin->module)) g_warning("%s: %s", plugin->filename, g_module_error()); else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.