Kaydet (Commit) 75a08ac4 authored tarafından Nick Treleaven's avatar Nick Treleaven

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.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1743 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 87fe0b95
......@@ -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>
......
......@@ -521,15 +521,17 @@ void init(PluginData *data)
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);
}
......
......@@ -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 @@ PluginFlags;
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;
......
......@@ -214,6 +214,12 @@ plugin_new(const gchar *fname)
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 @@ plugin_free(Plugin *plugin)
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment