From a2e76b7538ee60e3b2e56ec80f5a296315067696 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 23 Feb 2013 21:44:34 -0800 Subject: 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. --- src/evbp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3