summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2013-02-23 21:44:34 -0800
committerDan Nicholson <dbn.lists@gmail.com>2013-02-23 22:07:02 -0800
commita2e76b7538ee60e3b2e56ec80f5a296315067696 (patch)
tree1fe38708df255a81fb001eab13b2742792cc18f5
parent17a838b9b101dae9dac0a72f81f0892ee01dadd6 (diff)
evbp: Handle destruction appropriately
Without referencing the objects, the lifetimes of the plug and viewer were difficult to manage and the pointers could become invalid unexpectedly.
-rw-r--r--src/evbp.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/evbp.c b/src/evbp.c
index 648a621..a1a8dab 100644
--- a/src/evbp.c
+++ b/src/evbp.c
@@ -172,6 +172,7 @@ evbp_new(NPMIMEType pluginType, NPP instance, uint16_t mode,
/* create new viewer */
priv->viewer = evbp_viewer_new();
+ g_object_ref(priv->viewer);
gtk_widget_show(priv->viewer);
return NPERR_NO_ERROR;
@@ -184,8 +185,10 @@ evbp_destroy(NPP instance, NPSavedData **save)
g_debug("%s", __func__);
+ if (priv->viewer)
+ g_object_unref(priv->viewer);
if (priv->plug)
- gtk_widget_destroy(priv->plug);
+ g_object_unref(priv->plug);
npn_funcs->memfree(instance->pdata);
instance->pdata = NULL;
@@ -215,6 +218,7 @@ evbp_set_window(NPP instance, NPWindow *window)
g_debug("plugging into window id %lu", (unsigned long)id);
priv->plug = evbp_plug_new(id);
+ g_object_ref(priv->plug);
gtk_widget_set_size_request(priv->plug, window->width,
window->height);
gtk_container_add(GTK_CONTAINER(priv->plug), priv->viewer);