Refcounting craziness



Some code from bonobo-item-container.c (duplicated elsewhere a number of times):

void
bonobo_item_container_add (BonoboItemContainer *container, BonoboObject *client_site)
{
	container->client_sites = g_list_prepend (container->client_sites, client_site);

	gtk_signal_connect (GTK_OBJECT (client_site), "destroy",
			    GTK_SIGNAL_FUNC (bonobo_item_container_client_site_destroy_cb), container);
}

static void
bonobo_item_container_client_site_destroy_cb (BonoboClientSite *client_site, gpointer data)
{
	BonoboItemContainer *container = BONOBO_ITEM_CONTAINER (data);

	/*
	 * Remove this client site from our list.
	 */
	container->client_sites = g_list_remove (container->client_sites, client_site);
}

void
bonobo_item_container_remove (BonoboItemContainer *container, BonoboObject *client_site)
{
	container->client_sites = g_list_remove (container->client_sites, client_site);
}

static void
bonobo_item_container_destroy (GtkObject *object)
{
	BonoboItemContainer *container = BONOBO_ITEM_CONTAINER (object);

	/*
	 * Destroy all the ClientSites.
	 */
	while (container->client_sites) {
		BonoboClientSite *client_site =
			BONOBO_CLIENT_SITE (container->client_sites->data);

		bonobo_object_unref (BONOBO_OBJECT (client_site));
	}
	
	GTK_OBJECT_CLASS (bonobo_item_container_parent_class)->destroy (object);
}

What? What?? What??? 


I think you people need to rethink this some. Maybe a lot.

 - Does BonoboItemContainer own a reference count to its children? 

 - Does bonobo_item_container_add() assume a reference count on the
   child passed in? 

   [ Our policy in GTK+ is that we never do this, though the float/sink
     mechanism emulates this in a controllable way ]

 - What happens if someone else owns a reference count to one of the
   children of the item container?

 - What happens to the signal connection made in _add() when _remove()
   is called?


Regards,
                                        Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]