commit 675e01abed629f812212ef8c768dc55cd68b5079 Author: Simon McVittie Date: 2009-06-12 15:00:15 +0100 fd.o #22182: callable example: make sure we have a ref to the media stream for the whole time we're invoking one of its methods I want closures, or something :'-( diff --git a/examples/cm/callable/media-channel.c b/examples/cm/callable/media-channel.c index aaacada..9d90a9e 100644 --- a/examples/cm/callable/media-channel.c +++ b/examples/cm/callable/media-channel.c @@ -796,10 +796,15 @@ media_remove_streams (TpSvcChannelTypeStreamedMedia *iface, for (i = 0; i < stream_ids->len; i++) { + /* It's necessary to ref the stream while calling its close method, + * since the callback for removed will cause us to lose our only + * reference to it. */ guint id = g_array_index (stream_ids, guint, i); - - example_callable_media_stream_close ( + ExampleCallableMediaStream *stream = g_object_ref ( g_hash_table_lookup (self->priv->streams, GUINT_TO_POINTER (id))); + + example_callable_media_stream_close (stream); + g_object_unref (stream); } tp_svc_channel_type_streamed_media_return_from_remove_streams (context); @@ -838,9 +843,11 @@ media_request_stream_direction (TpSvcChannelTypeStreamedMedia *iface, * * if (stream_direction == TP_MEDIA_STREAM_DIRECTION_NONE) * { + * g_object_ref (stream); * example_callable_media_stream_close (stream); * tp_svc_channel_type_streamed_media_return_from_request_stream_direction ( * context); + * g_object_unref (stream); * return; * } *